Reputation: 119
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.
Upvotes: 3
Views: 544
Reputation: 2795
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();
}
Upvotes: 1