Last active
July 19, 2020 07:45
-
-
Save GautamPanickar/6ed1a0fcebc0c5a826b0fecf58010c70 to your computer and use it in GitHub Desktop.
Service worker with Google's Workbox for Angular App - main file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { enableProdMode } from '@angular/core'; | |
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | |
import { AppModule } from './app/app.module'; | |
import { environment } from './environments/environment'; | |
import {Workbox} from 'workbox-window'; | |
if (environment.production) { | |
enableProdMode(); | |
} | |
function loadServiceWorker() { | |
console.log('Hey , Lemme check if I can load the service worker. SW will load in production only!'); | |
if ('serviceWorker' in navigator && environment.production) { | |
console.log('Okay, the browser supports service worker. That is encouraging!'); | |
const wb = new Workbox('service-worker.js'); | |
wb.register(); | |
} else { | |
console.log('Service worker could not be loaded.') | |
} | |
} | |
platformBrowserDynamic().bootstrapModule(AppModule) | |
.then(_ => loadServiceWorker()) | |
.catch(err => console.error(err)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment