Added service worker regisration refresh BOD-73

This commit is contained in:
Patrick Fic
2020-08-21 12:47:54 -07:00
parent 97629a91fb
commit f29b961397
9 changed files with 117 additions and 7 deletions

View File

@@ -58,6 +58,16 @@ function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then((registration) => {
// Start addition---
// https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#manual_updates
// Added code, as our application will be open for a long time and we are a SPA, we need
// to trigger checks for updates frequently
setInterval(() => {
console.log("Checking if service worker was updated in server");
registration.update();
}, 15 * 60 * 1000); // Every 15 mins check
// End addition---
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {