Jay
Jay

Reputation: 493

Check for service worker updates periodically

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.

Upvotes: 6

Views: 2796

Answers (1)

Joey Driessen
Joey Driessen

Reputation: 318

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.

Upvotes: 4

Related Questions