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)

Configuring the Service Worker


In the previous section, we added the service worker configuration file src/ngsw-config.json to our project, but we have not configured anything yet.

In this section, we will add two types of configurations: asset groups and data groups.

Asset and Data Groups

In the asset groups configuration, we specify how we want our service worker to handle the assets of our application. When we talk about assets, we should think of style sheets, images, external JS files, and so on.

Asset groups are defined using the following TypeScript interface:

interface AssetGroup {
  name: string;
  installMode?: 'prefetch' | 'lazy';
  updateMode?: 'prefetch' | 'lazy';
  resources: {
    files?: string[];
    versionedFiles?: string[];
    urls?: string[];
  };
}

Here's what the parameters mean:

  • name uniquely identifies the group of assets

  • installMode defines how new resources are initially cached

  • updateMode defines the caching behavior of existing resources

  • The resources object describes...