ric*_*son 2 javascript browser service-worker progressive-web-apps angular
I'm trying to add a service worker to my (already existing) project. but when i open the browser, i see that it doesn't get the service worker.
These are the steps i followed:
ng add @angular/pwa --project <my-project-name>
to my projectng build --prod
http-server -p 8080 -c-1 dist/<my-project-name>
Now, the app is running, and it does get the manifest file but not the service worker:
manifest.webmanifest:
ngsw-config.json:
When i tried to do all of the steps above on a brand new project it did work and got the service worker. but not on my already existing project.
尝试将 service worker 设置为registerImmediately
这样:
ServiceWorkerModule.register('ngsw-worker.js', {
enabled: environment.production,
registrationStrategy: 'registerImmediately',
})
Run Code Online (Sandbox Code Playgroud)
如果您有一个使用类似setInterval
service worker的第三方库,则永远不会注册。这是因为默认registerWhenStable
依赖于isStable
重复性任务永远不会发生。
如果您在应用程序启动时启动任何类型的循环异步任务,应用程序将永远不会稳定(例如,对于轮询过程,以 setInterval、setTimeout 或使用 RxJS 运算符(如 interval)启动);
归档时间: |
|
查看次数: |
1245 次 |
最近记录: |