Skip to content

Instantly share code, notes, and snippets.

@webmaxru
Last active August 30, 2017 20:46
Show Gist options
  • Save webmaxru/7dc8b51ee2b931f3a9a1b110e335a6c9 to your computer and use it in GitHub Desktop.
Save webmaxru/7dc8b51ee2b931f3a9a1b110e335a6c9 to your computer and use it in GitHub Desktop.
platformBrowserDynamic()
.bootstrapModule(AppModule)
.then(() => {
registerServiceWorker('sw-default')
});
function registerServiceWorker(swName: string) {
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register(`/${swName}.js`)
.then(reg => {
console.log('[App] Successful service worker registration', reg);
})
.catch(err =>
console.error('[App] Service worker registration failed', err)
);
} else {
console.error('[App] Service Worker API is not supported in current browser');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment