Book Image

Beginning Server-Side Application Development with Angular

By : Bram Borggreve
Book Image

Beginning Server-Side Application Development with Angular

By: Bram Borggreve

Overview of this book

Equip yourself with the skills required to create modern, progressive web applications that load quickly and efficiently. This fast-paced guide to server-side Angular leads you through an example application that uses Angular Universal to render application pages on the server, rather than the client. You'll learn how to serve your users views that load instantly, while reaping all the SEO benefits of improved page indexing. With differences of just 200 milliseconds in performance having a measurable impact on your users, it's more important than ever to get server-side right.
Table of Contents (10 chapters)

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...