0

I want to make a PWA app with Angular 19 that is available offline. I followed the official documentation to install the ServiceWorker. But when I simulate the offline status in the browser, the app is not available. I have tried running it with ng serve --configuration=production or with npx http-server -p 8080 -c-1 dist/browser but it didn't change anything.

The worker is registered like this:

export const appConfig: ApplicationConfig = {
  providers: [
    provideHttpClient(),
    provideZoneChangeDetection({ eventCoalescing: true }),
    provideRouter(routes), provideServiceWorker('ngsw-worker.js', {
            enabled: !isDevMode(),
            registrationStrategy: 'registerWhenStable:30000'
          }),
  ],
};

I have also tried registerImmediately:30000, didn't help either.

Is there anything else I must do to get the worker working?

3
  • are you using https, as it is a requirement for service worker to work? Commented Oct 15 at 15:18
  • I don't but the documentation says: If you are not using HTTPS, the service worker will only be registered when accessing the application on localhost. which I do. Commented Oct 16 at 6:11
  • I've just tried it with the self signed certificate, but that doesn't change anything. Commented Oct 16 at 7:50

1 Answer 1

0

Apparently it is not enough to run ng build as the documentation states. It needs to be ng build --configuration=production

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.