Progressive Web App with Angular 11

17/04/21 dannyVersion Française

What are we going to do?

We will turn our Standard Web Application into a PWA (Progressive Web App)
We will use the Angular version 11.2.10 javascript framework.

This is Step 8 of our  Angular guide which will allow us to obtain a PWA Web Application.
We will use an existing project whose characteristics are

  • Generated with Angular CLI
  • Routing
  • Lazy Loading
  • Framework CSS Bootstrap
  • Server Side Rendering
  • HttpClient
  • Transfer State

All created sources are indicated at the end of the tutorial.

The application is at the following address

Before you start

2008 App Store is an application store distributed by Apple on mobile devices running iOS.
2012 Google Play Store is an online application store created by Google.

2014, the global annual sales of smartphones exceed one billion units.

2017 two operating systems for mobile is sharing the global smartphone market.
Android 85.1 %  and IOS 14.8%

More than 50% of Internet searches are now done on mobile in France.

Android and iOS operating systems are written in different programming languages.
IOS applications work on Objective-C / Swift, while Android applications run on Java.

If you want to develop a mobile application, you can either develop a specific version for each platform or use a cross platform tool that will allow you to have only one source for both OS.
It will still manage registration on the app store.
In all cases users must go to a download platform to install an app.

In 2015, Frances Berriman and Google engineer Alex Russell propose the term "progressive web apps"

A PWA looks like a regular website, from a secure URL but allows a user experience similar to that of a mobile application, without the constraints of the latter (submission to App Stores, significant use of the device memory


We will use the Angular documentation to apply this technique.

We will use the command angular-cli
ng add

# Ajout de la librairie pwa
ng add @angular/pwa --project angular-starter

Angular-cli automatically made a number of changes to our project.

  • modify the package.json file (in this example we will update dependencies and descriptors)
  • edit angular.json file
  • creating the ngsw-config.json file
  • creating the src/manifest.webmanifest file
  • edit src/index.html file
  • edit src/app.browser.module.ts file
  • icons creationsrc/app/assets/icons
  "dependencies": {
    "@angular/animations": "11.2.10",
    "@angular/common": "11.2.10",
    "@angular/compiler": "11.2.10",
    "@angular/core": "11.2.10",
    "@angular/forms": "11.2.10",
    "@angular/platform-browser": "11.2.10",
    "@angular/platform-browser-dynamic": "11.2.10",
    "@angular/platform-server": "11.2.10",
    "@angular/router": "11.2.10",
    "@angular/service-worker": "11.2.10",
    "@fortawesome/fontawesome-free": "5.15.3",
    "@nguniversal/express-engine": "11.2.1",
    "bootstrap": "4.6.0",
    "express": "4.17.1",
    "jquery": "3.6.0",
    "rxjs": "6.6.7",
    "tslib": "2.2.0",
    "zone.js": "0.11.4"
  "devDependencies": {
    "@angular-devkit/build-angular": "0.1102.9",
    "@angular/cli": "11.2.9",
    "@angular/compiler-cli": "11.2.10",
    "@nguniversal/builders": "11.2.1",
    "@types/express": "4.17.11",
    "@types/jasmine": "3.6.9",
    "@types/node": "14.14.41",
    "codelyzer": "6.0.1",
    "jasmine-core": "3.7.1",
    "jasmine-spec-reporter": "7.0.0",
    "karma": "6.3.2",
    "karma-chrome-launcher": "3.1.0",
    "karma-coverage": "2.0.3",
    "karma-jasmine": "4.0.1",
    "karma-jasmine-html-reporter": "1.5.4",
    "protractor": "7.0.0",
    "ts-node": "9.1.1",
    "tslint": "6.1.3",
    "typescript": "4.1.5"

"assets": [


"configurations": {
    "production": {
      "fileReplacements": [
          "replace": "src/environments/environment.ts",
          "with": "src/environments/"
      "optimization": true,
      "outputHashing": "all",
      "sourceMap": false,
      "extractCss": true,
      "namedChunks": false,
      "extractLicenses": true,
      "vendorChunk": false,
      "buildOptimizer": true,
      "budgets": [
          "type": "initial",
          "maximumWarning": "2mb",
          "maximumError": "5mb"
          "type": "anyComponentStyle",
          "maximumWarning": "6kb",
          "maximumError": "10kb"
      "serviceWorker": true,
      "ngswConfigPath": "ngsw-config.json"
  "$schema": "./node_modules/@angular/service-worker/config/schema.json",
  "index": "/index.html",
  "assetGroups": [
      "name": "app",
      "installMode": "prefetch",
      "resources": {
        "files": [
    }, {
      "name": "assets",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "resources": {
        "files": [
  "name": "angular-starter",
  "short_name": "angular-starter",
  "theme_color": "#1976d2",
  "background_color": "#fafafa",
  "display": "standalone",
  "scope": "/",
  "start_url": "/",
  "icons": [
      "src": "assets/icons/icon-72x72.png",
      "sizes": "72x72",
      "type": "image/png"
      "src": "assets/icons/icon-96x96.png",
      "sizes": "96x96",
      "type": "image/png"
      "src": "assets/icons/icon-128x128.png",
      "sizes": "128x128",
      "type": "image/png"
      "src": "assets/icons/icon-144x144.png",
      "sizes": "144x144",
      "type": "image/png"
      "src": "assets/icons/icon-152x152.png",
      "sizes": "152x152",
      "type": "image/png"
      "src": "assets/icons/icon-192x192.png",
      "sizes": "192x192",
      "type": "image/png"
      "src": "assets/icons/icon-384x384.png",
      "sizes": "384x384",
      "type": "image/png"
      "src": "assets/icons/icon-512x512.png",
      "sizes": "512x512",
      "type": "image/png"
<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="manifest" href="manifest.webmanifest">
  <meta name="theme-color" content="#1976d2">
  <noscript>Please enable JavaScript to continue using this application.</noscript>
import { NgModule } from '@angular/core';
import { BrowserModule, BrowserTransferStateModule } from '@angular/platform-browser';

import { AppModule } from './app.module';
import { AppComponent } from './app.component';
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';

  imports: [
    BrowserModule.withServerTransition({ appId: 'angular-starter' }),
    ServiceWorkerModule.register('ngsw-worker.js', {
      enabled: environment.production,
      // Register the ServiceWorker as soon as the app is stable
      // or after 30 seconds (whichever comes first).
      registrationStrategy: 'registerWhenStable:30000'
  bootstrap: [AppComponent],
export class AppBrowserModule { }


Nous allons tester le fonctionnement de la PWA

The npm run start script executes the ng serve command
ng serve does not work with service workers

To test, you must use an http server.

Les scripts suivants pemettent donc de tester notre pwa

  • npm run build:ssr
  • npm run serve:ssr
  • http://localhost:4000/


All you have to do is open Chrome development tools with Ctrl + Maj + J
And run a test of the Lighthouse tool

  • Audits
  • Run audits