未检测到服务人员
Service worker not detected
我正在使用 service worker 构建一个 angular 9 PWA。我遵循了官方指南来增强 service worker 并且一切正常,直到今天,当我注意到我的应用程序不再具有 sw 功能(缓存、可安装性等)
灯塔状态:
Does not register a service worker that controls page and start_url
事实是,我没有触及它的任何东西,所以我无法弄清楚哪里出了问题。
ngsw.json:
{
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/manifest.webmanifest",
"/*.css",
"/*.js"
]
}
},
{
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
]
}
}
],
"dataGroups": [
{
"name": "configs",
"urls": [
"active-profile",
"configurations"
],
"cacheConfig": {
"maxSize": 1,
"maxAge": "2d",
"strategy": "performance"
}
},
{
"name": "searches",
"urls": [
"search"
],
"cacheConfig": {
"maxSize": 1,
"maxAge": "15m",
"strategy": "performance"
}
}
]
}
这里是清单:
{
"name": "Shootbook",
"short_name": "Shootbook",
"theme_color": "#fafafa",
"background_color": "#fff",
"display": "standalone",
"scope": "/",
"start_url": "/",
"icons": [
{
"src": "assets/icons/icon-72x72.png",
"sizes": "72x72",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "assets/icons/icon-96x96.png",
"sizes": "96x96",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "assets/icons/icon-128x128.png",
"sizes": "128x128",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "assets/icons/icon-144x144.png",
"sizes": "144x144",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "assets/icons/icon-152x152.png",
"sizes": "152x152",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "assets/icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "assets/icons/icon-384x384.png",
"sizes": "384x384",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "assets/icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any maskable"
}
]
}
有什么想法吗?
我找到了解决方案:似乎 Angular 等待应用程序“稳定”(无论这意味着什么......)。要覆盖此行为,只需将 registrationStrategy
设置为 'registerImmediately'
:
ServiceWorkerModule.register('ngsw-worker.js', {
enabled: environment.production,
registrationStrategy: 'registerImmediately',
})
我正在使用 service worker 构建一个 angular 9 PWA。我遵循了官方指南来增强 service worker 并且一切正常,直到今天,当我注意到我的应用程序不再具有 sw 功能(缓存、可安装性等)
灯塔状态:
Does not register a service worker that controls page and start_url
事实是,我没有触及它的任何东西,所以我无法弄清楚哪里出了问题。
ngsw.json:
{
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/manifest.webmanifest",
"/*.css",
"/*.js"
]
}
},
{
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
]
}
}
],
"dataGroups": [
{
"name": "configs",
"urls": [
"active-profile",
"configurations"
],
"cacheConfig": {
"maxSize": 1,
"maxAge": "2d",
"strategy": "performance"
}
},
{
"name": "searches",
"urls": [
"search"
],
"cacheConfig": {
"maxSize": 1,
"maxAge": "15m",
"strategy": "performance"
}
}
]
}
这里是清单:
{
"name": "Shootbook",
"short_name": "Shootbook",
"theme_color": "#fafafa",
"background_color": "#fff",
"display": "standalone",
"scope": "/",
"start_url": "/",
"icons": [
{
"src": "assets/icons/icon-72x72.png",
"sizes": "72x72",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "assets/icons/icon-96x96.png",
"sizes": "96x96",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "assets/icons/icon-128x128.png",
"sizes": "128x128",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "assets/icons/icon-144x144.png",
"sizes": "144x144",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "assets/icons/icon-152x152.png",
"sizes": "152x152",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "assets/icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "assets/icons/icon-384x384.png",
"sizes": "384x384",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "assets/icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any maskable"
}
]
}
有什么想法吗?
我找到了解决方案:似乎 Angular 等待应用程序“稳定”(无论这意味着什么......)。要覆盖此行为,只需将 registrationStrategy
设置为 'registerImmediately'
:
ServiceWorkerModule.register('ngsw-worker.js', {
enabled: environment.production,
registrationStrategy: 'registerImmediately',
})