I am registering ngsw-worker.js in both main.ts and app.module.ts. Is this ok?
Such as would it create 2 instances of service worker? Would there be a conflict in service worker?
main.ts
platformBrowserDynamic().bootstrapModule(AppModule).then(() => {
if ('serviceWorker' in navigator && environment.production) {
navigator.serviceWorker.register('/ngsw-worker.js');
}
}).catch(err => console.log(err));
app.module.ts
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
ServiceWorkerModule.register('/ngsw-worker.js', {enabled: environment.production}),
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
}
I am registering it in main.ts because of this reason.
It's registered in app.module.ts because default Angular-cli SW project adds it here.
After registering the service workers in both main.ts and app.module.ts, I add Firebase Cloud Messaging sdk to the Service Worker instances.
navigator.serviceWorker
.ready
.then((registration) => this.firebase.messaging().useServiceWorker(registration));
So in brief, registering two instances of ngsw-worker.js would this be a problem?