Existing App does not get Service Worker capabilities
See original GitHub issueVersions
Angular CLI: 1.6.0
Node: 9.2.0
OS: win32 x64
Angular: 5.1.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker
@angular/cli: 1.6.0
@angular-devkit/build-optimizer: 0.0.35
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.41
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.0
@schematics/angular: 0.1.10
@schematics/schematics: 0.0.10
typescript: 2.6.2
webpack: 3.10.0
Repro steps
Have an existing app with no PWA capability and apply steps to upgrade it as described in docs.
Observed behavior
Despite the fact it builds with no error and dist
folder has files like ngsw.json
& ngsw-worker.js
as expected, they are not loaded on network request when browsed. (Tested with incognito mode as well)
No service-worker effect at all in app.
Desired behavior
Service Worker added to built app when steps in official docs are applied.
Mention any other details that might be useful
On the same machine, a new app generated with Angular-CLI 1.6.0 with --service-worker
flag. That app loads service worker as expected.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:28
- Comments:53 (5 by maintainers)
Top Results From Across the Web
Using Service Workers - Web APIs | MDN
This article provides information on getting started with service workers, including basic architecture, registering a service worker, ...
Read more >Handling Service Worker updates – how to keep the app ...
Not applying the Service Worker update might mean that our outdated Service Worker runs for ages and serves our users with assets from...
Read more >Service workers - web.dev
Not all browsers support service workers. Even when present your service worker won't be available on first load or while it's waiting to...
Read more >Progressive Web Apps with Service Workers | by Jesse Yang
In this post we will discuss Progressive Web Apps and Service Workers. How can they help modern-day mobile web users, and how are...
Read more >Powering Up Your Web Apps With Service Workers
Since the existing service worker will still serve the cached web page and not the one with the newly created service worker file,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I also had this issue, the culprit seams to be angularFire2. I worked around it by registering the service worker in main.ts.
Service worker won’t run because of ng app is not stable (ApplicationRef.isStable (https://angular.io/api/core/ApplicationRef#members), application is not becoming stable if there is a code which runs intervals (setInteral or Observable.timer and etc. which come from setInterval or setTimeout (related with NgZone.hasPendingMicrotasks)).
As example of such behaviour:
ng new my-project --service-worker
;setInterval(t => { console.log('Ping')}, 500);
Workaround for such behaviour wrap - wrap all timer-code to
this.applicationRef.isStable.subscribe(isStable => { if (isStable) { <code goes here> } })
Full code