gpt4 book ai didi

angular - 我的 angular 7 PWA 在离线时找不到文件 'ngsw.json'

转载 作者:行者123 更新时间:2023-12-03 21:04:00 27 4
gpt4 key购买 nike

我正在做一个 PWA 应用程序并且它运行良好(通过 Chorme 的审计)但是当我想在离线模式下尝试它时。出现 504 TIMEOUT 错误。 DevsTools(Chorme) 显示“获取脚本时发生未知错误,
无法加载资源:net::ERR_INTERNET_DISCONNECTED' 并且当应用程序尝试获取“ngsw.json?ngsw-cache-bust=0.30493506524068925”时,网络切片显示失败

这是我的包裹:

{
"name": "avl",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^7.2.8",
"@angular/cdk": "^7.3.4",
"@angular/common": "~7.2.0",
"@angular/compiler": "~7.2.0",
"@angular/core": "~7.2.0",
"@angular/flex-layout": "^7.0.0-beta.24",
"@angular/forms": "~7.2.0",
"@angular/http": "^7.2.8",
"@angular/material": "^7.3.4",
"@angular/platform-browser": "~7.2.0",
"@angular/platform-browser-dynamic": "~7.2.0",
"@angular/pwa": "^0.13.8",
"@angular/router": "~7.2.0",
"@angular/service-worker": "^7.2.13",
"@mapbox/leaflet-pip": "^1.1.0",
"@types/fontfaceobserver": "^0.0.6",
"@types/leaflet": "^1.4.3",
"@types/pixi.js": "4.7.2",
"cerialize": "^0.1.18",
"core-js": "^2.5.4",
"fontfaceobserver": "^2.1.0",
"leaflet-pixi-overlay": "^1.6.0",
"moment": "^2.24.0",
"net": "^1.0.2",
"pixi.js": "4.7.2",
"rxjs": "~6.3.3",
"rxjs-compat": "6.3.3",
"tslib": "^1.9.0",
"wellknown": "^0.5.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.13.7",
"@angular/cli": "~7.3.3",
"@angular/compiler-cli": "~7.2.0",
"@angular/language-service": "^7.2.8",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.2.2"
}
}

这是我的 ngsw-config.json
{
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/*.css",
"/*.js",
"/*.json"
]
}
}, {
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani|json)"
]
}
}
]
}

我希望用他的 css 看到应用程序的 html

最佳答案

网络 list 在我看来是正确的。

服务 worker 不与 ng serve 一起工作.因此,您必须进行 prod 构建(ng build --prod)并使用 Web 服务器在本地提供已编译的代码。

为了验证您的 Service Worker 是否已正确安装并正在运行:

  • 打开 Chrome 开发工具
  • 访问“应用程序”选项卡
  • 点击“Service Worker”链接(左侧)

  • 如果 service worker 正在运行,它将显示在那里。

    我写了一个 step by step guide为了创建一个 Angular PWA(在 Github 上还有一个最终的 DEMO),也许你可以跟着它,看看是否缺少任何东西。

    关于angular - 我的 angular 7 PWA 在离线时找不到文件 'ngsw.json',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55694709/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com