Reputation: 11
I Added PWA package to my angular application. Angular CLI version is 15.2.9 and serviceworker version is also 15.2.9. I am facing an issue with the service worker. The service worker is registered on its own through the app.module. It works fine in online mode. But when I change the network to offline mode,local configured json flies are not loading and ngsw.json?ngsw-cache-bust failing.
serverconfig file is not loading.
expecting to work the pwa application in offline mode.
Upvotes: 1
Views: 197
Reputation: 41
In your application app.modules.ts
, did you register the service worker?
ServiceWorkerModule.register('ngsw-worker.js', {
enabled: true,
// Register the ServiceWorker as soon as the application is stable
// or after 30 seconds (whichever comes first).
registrationStrategy: 'registerWhenStable:30000',
}),
If yes, make sure you enabled it as in my sample above, or to build you application using ng build --configuration production
. You can also run your application in production configuration by using ng serve --configuration production
.
If this still didn't help you can test in the developer tools if your service workers are actually started and trying to cache your application.
In case it does, the next thing to check is to set the application in offline mode and see if it does return any of your content successfully, when it did load the page in online mode once successfully.
Upvotes: 0