0

We have a SAP Spartacus PWA application and have some requirements to work some portions of this application in offline mode. Below are the issues:

  1. The offline mode is working partially. like if a page/component is visited first and revisit then its working but when it gets visited first time in offline mode, it shows blank page.

  2. The homepage is not getting displayed in offline mode if the application is getting opened first time.

By default service worker code generated by angular cli as below:

ngsw-config.json

{
  "$schema": "./node_modules/@angular/service-worker/config/schema.json",
  "index": "/index.html",
  "assetGroups": [
    {
      "name": "app",
      "installMode": "prefetch",
      "resources": {
        "files": [
          "/favicon.ico",
          "/index.html",
          "/manifest.webmanifest",
          "/*.css",
          "/*.js"
        ]
      }
    },
    {
      "name": "assets",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "resources": {
        "files": [
          "/assets/**",
          "/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
        ]
      }
    }
  ]
}

in app.module.ts

 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'
    }),

in angular.json

"serviceWorker": true,
"ngswConfigPath": "ngsw-config.json"

Can anyone please help?

bappa147
  • 519
  • 3
  • 8
  • 18

0 Answers0