Angular 7 - service worker not registered

前端 未结 3 837
余生分开走
余生分开走 2020-12-29 05:15

I did everything as written in \"https://angular.io/guide/service-worker-getting-started\" to make my application PWA.

Used exactly this commands:

n         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 05:27

    artemisian's solution works but it's a hack, and you're not sure if it will work in the future.

    A better solution

    There is a 'registrationStrategy' setting which has to do with angular waiting with the registration until your app is 'stable'. Now if you have a bunch of stuff loading while starting your app (authenticating and building websocket connections) angular apparently thinks your app never is stable.

    Fortunately you can override the registrationStrategy to registerImmediately like so:

    ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production, registrationStrategy: 'registerImmediately' }),
    

    See for the documentation here

    After this the serviceworker will load, whatever the state of your app. There's also an option to pass an observable, so you can have it loaded whenever you think it's right.

提交回复
热议问题