我正在执行PWA应用,并且运行良好(通过了Chorme的审核),但是当我想在脱机模式下尝试时。出现504超时错误。 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
答案 0 :(得分:0)
网络清单对我来说看起来是正确的。
服务人员无法使用ng serve
。因此,您必须执行一个prod build(ng build --prod),然后使用Web服务器在本地提供已编译的代码。
为了验证您的服务工作者是否已正确安装并正在运行:
如果服务工作者正在运行,它将显示在此处。
我写了一个step by step guide来创建Angular PWA(Github上还有一个最终的DEMO),也许您可以遵循它,看看是否有任何遗漏。