Prefetch API calls with service worker

495 Views Asked by At

I have setup service worker for my angular app. The caching of the data groups works fine as long as the relevant page that the API call is made is visited. However my goal is to on the load of the application cache the data of all the endpoints specified in the ngsw-config. Tried using the example provided for swUpdate that is :

swUpdate.available.subscribe(event => {
      swUpdate.activateUpdate().then(() => document.location.reload());
    }); 

on the start of the application in the constructor of my appcomponent, but no luck. Any help is appreciated. TIA.

1

There are 1 best solutions below

4
On

it need to download metadata from server try as follow

    swUpdate.available.subscribe(event => {
      swUpdate.activateUpdate().then(() => document.location.reload());
    });
    if(swUpdate.isEnabled) {
      swUpdate.checkForUpdate();
    }