Search code examples
javascriptangularservice-workerprogressive-web-appsangular-router

Lazy loading or preloading Angular modules and using a service worker to cache results?


Does the Angular CLI approach to progressive web apps include a way to cache preloaded or lazy loaded modules using a service worker (Progressive Web App) approach?

For example the Angular Router has a PreloadAllModules strategy, so just curios if this can be combined or is combined with service worker caching?

In other words configure the generated service worker to cache all resources preloaded with the PreloadAllModules strategy.


Solution

  • Yes, I believe you can set up your ServiceWorker to lazy-load your modules in the background. The CLI provides tooling for this, see:

    https://angular.io/guide/service-worker-getting-started

    This article also provides a thorough explanation:

    https://blog.angular-university.io/angular-service-worker/