5
votes

How do I poll the server every minute to check the service worker update?

I have used the available method of SWUpdate angular, but it doesn't poll the server, instead it fetched the updates and caches when the page is refreshed which is not required.

I came across checkForUpdate() method, which does quite similar, but not sure of how it works?

Any of the help would be appreciated.

ngOnInit(){

   if(this.swUpdate.isEnabled){
     this.swUpdate.available.subscribe( () => {

       if(confirm("New Version available.. Load?")){
         window.location.reload();
       }


     })
   }

 }

Above code which fetches the data from cache on the second reload.

1
The service worker by default checks for any new SW update (filesize difference). Then depending on how the SW is programmed, it can either refresh the page to load the new content or just stays the same until the next refresh/load - oninross

1 Answers

4
votes

If it is still relevant you can do something like this: setInterval(function(){ swUpdate.checkForUpdate(); }, 1000);

This will check every second if there is a new version of you application. When it finds the new version it will go in the available once it got the new version downloaded.

Hope this might still help you and is what you are looking for.