I did everything as written in "https://angular.io/guide/service-worker-getting-started" to make my application PWA.
Used exactly this commands:
ng add @angular/pwa npm install http-server -g ng build --prod http-server -p 8080 -c-1 dist
Then I opened this url on Chrome (in incognito)
http://127.0.0.1:8080
When I open tools for developers (f12) > Applications > Service Workers there is no service worker available and website don't work when I set offline there.
Additional info about my angular app:
package.json: (the most important ones)
"@angular/core": "^7.0.2", "@angular/pwa": "^0.10.6", "@angular/service-worker": "^7.0.4", "@angular-devkit/build-angular": "^0.10.6", "@angular/cli": "^7.0.6",
The ngsw-config.json configuration file specifies which files and data URLs the Angular service worker should cache and how it should update the cached files and data. The Angular CLI processes the configuration file during ng build .
Subscribe to update notifications from the Service Worker, trigger update checks, and forcibly activate updates.
Note that ngsw stands for Angular Service Worker. We will cover these two files in detail, right now let's see what else the CLI has added for PWA support.
Adding a service worker to an Angular application is one of the steps for turning an application into a Progressive Web App (also known as a PWA). At its simplest, a service worker is a script that runs in the web browser and manages caching for an application. Service workers function as a network proxy.
It seems the service worker setup is broken for the @angular/[email protected]:
As a temporary solution you can register it manually yourself by modifying the file src/main.ts (Once fixed you can remove the manual service worker registration.):
..... platformBrowserDynamic().bootstrapModule(AppModule).then(() => { if ('serviceWorker' in navigator && environment.production) { navigator.serviceWorker.register('/ngsw-worker.js'); } }).catch(err => console.log(err));
PS: Github issue created: https://github.com/angular/angular-cli/issues/13351
PS: Github issue #2 created: https://github.com/angular/angular-cli/issues/15025
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With