Check Service worker installation progress from component (angular)

我与影子孤独终老i 提交于 2019-12-04 18:33:45

You can enhance your Angular service worker behaviour using the technique described here (link broken):

http://jakubcodes.pl/2018/06/13/enhancing-angular-ngsw/

It basically registers an intermediate script file as the service worker JavaScript file and in this, the Angular script besides own code is called.

Edit

The process in detail:

  1. Create two js files in your src folder (e.g. "sw-master.js" and "sw-custom.js"). The latter may contain your custom service worker code.
  2. Add these two lines to your "sw-master.js" (import the custom script before the NGSW script):

    importScripts('./sw-custom.js');
    importScripts('./ngsw-worker.js');
    
  3. Register the two new assets in the "angular.json" file of your project:

    "assets": [
      "src/favicon.ico",
      "src/assets",
      "src/manifest.json",
      "src/sw-master.js",
      "src/sw-custom.js"
    ],
    
  4. Register the master script instead of "ngsw-worker.js" in your "app.module.ts":

    ServiceWorkerModule.register('/sw-master.js', { enabled: environment.production })
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!