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[]; }; ...

Get Beginning Server-Side Application Development with Angular now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.