Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prefetch API calls with service worker

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.

like image 783
Clueless Avatar asked Dec 02 '25 10:12

Clueless


1 Answers

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();
    }
like image 159
Radik Avatar answered Dec 04 '25 02:12

Radik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!