From 3e4dffd7a4d488a18c195fe82d593737ed168193 Mon Sep 17 00:00:00 2001 From: Sean Engelhardt Date: Tue, 5 Mar 2019 14:06:36 +0100 Subject: [PATCH] Add Service Work(e|a)r(round) uses the promise in returned by .bootstrapModule to register the serviceworker if required. Seems to work reliable, even in unstable environments. Requires production mode to comprehend. (at least ng build --prod) --- client/src/main.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/src/main.ts b/client/src/main.ts index cbf340b02..f9561edd5 100644 --- a/client/src/main.ts +++ b/client/src/main.ts @@ -10,4 +10,9 @@ if (environment.production) { platformBrowserDynamic() .bootstrapModule(AppModule) + .then(() => { + if ('serviceWorker' in navigator && environment.production) { + navigator.serviceWorker.register('ngsw-worker.js'); + } + }) .catch(err => console.log(err));