0

We have an angular webapp which should work offline only if used as standalone web app (pwa), but not in the "normal" browser mode. Only very few users need the offline feature, but when angular pwa is enabled, all users will get the "last cached" version of the app and we have to display an alert and reload the page if there are software updates (which happens quite often).

We want the website to ignore all service workers, only when used as installed standalone web app the service workers should drop in.

Is that possible? I could not find any solution so far.

Nico
  • 1
  • 2

1 Answers1

0

I found a solution myself: it works, by setting the enabled flag conditionally:

ServiceWorkerModule.register('ngsw-worker.js', {
  enabled: environment.production && 
    (navigator['standalone'] || window.matchMedia('(display-mode: standalone)').matches),
}),
Nico
  • 1
  • 2