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.
A: From a page on the same origin, go to Developer Tools > Application > Service Workers. You can also use chrome://inspect/#service-workers to find all running service workers.
The update() method of the ServiceWorkerRegistration interface attempts to update the service worker. It fetches the worker's script URL, and if the new worker is not byte-by-byte identical to the current worker, it installs the new worker.
There is no way to prevent ServiceWorker from stopping. Instead, ServiceWorker automatically starts again when necessary, for example, when a push message arrives.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With