How to add URL dynamically to angular service worker DataGroup

Discussão em 'Angular' iniciado por Samuel Shyu, Julho 23, 2025.

  1. Samuel Shyu

    Samuel Shyu Guest

    I am using @angular/service-worker to build a PWA application. Angular service-worker adds the ngsw-config.json file, in which you can add a "dataGroups" section to configure cache urls and strategy, etc.

    "dataGroups": [{
    "name": "tile-cache",
    "urls": [
    ],
    "cacheConfig": {
    "strategy": "performance",
    "maxSize": 10000,
    "maxAge": "30d"
    }
    }].


    In my application, I need to add cached urls(like some external map tiles urls) dynamically to the service worker CacheStorage instead of pre-configuring them in dataGroups of the ngsw-config.json file.

    I don't see @angular/service-worker exposing any public class or method for doing this. Is there anyone who knows how to achieve this?

    Continue reading...

Compartilhe esta Página