Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Beginning Server-Side Application Development with Angular

You're reading from   Beginning Server-Side Application Development with Angular Discover how to rapidly prototype SEO-friendly web applications with Angular Universal

Arrow left icon
Product type Paperback
Published in Apr 2018
Publisher
ISBN-13 9781789342161
Length 110 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Bram Borggreve Bram Borggreve
Author Profile Icon Bram Borggreve
Bram Borggreve
Arrow right icon
View More author details
Toc

Enabling the Service Worker


Now that the dependency is installed, it's time to enable the service worker.

This involves three steps:

  1. Enabling the service worker in our browser app in .angular-cli.json.

  2. Importing and registering the ServiceWorkerModule in our AppModule.

  3. Creating the service worker configuration file src/ngsw-config.json.

We will use the ng set command to enable support for the service worker in our browser app in .angular-cli.json:

  1. Open the terminal in the project directory.

  2. Run the following command to adjust .angular-cli.json:

    ng set apps.0.serviceWorker=true
  3. Confirm that the property serviceWorker is set to true in the first app in the apps array in .angular-cli.json:

Importing the ServiceWorkerModule

We will import the ServiceWorkerModule in our AppModule and register it.

We will invoke the register method on the ServiceWorkerModule. This method takes two parameters. The first parameter defines what the location of the Angular service worker is. The value '/ngsw-worker.js' is what...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime