Reputation: 139
Is there a way to compare the current service worker to the one on the server without moving between pages or refreshing the current page? My app is mainly 1 page and users pretty much never move between pages.
I've found multiple ways to detect service worker updates when navigating between pages or refreshing (adding event listener for updatefound for example). So far I have a working visibilityChange event which triggers correctly whenever I would like to detect service worker updates but struggle to find a way to actually detect them.
Upvotes: 2
Views: 1399
Reputation: 5253
You can force the browser to check for a new Service Worker by calling registration.update(). This also installs the new SW if there's one.
https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/update
Upvotes: 3