-
-
Save joshwiens/328f2abf47f2e244f7457b0c01daa4d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof window!=='undefined' && navigator.serviceWorker && navigator.serviceWorker.controller) { | |
let reloadOnNext = false; | |
let pushState = history.pushState; | |
history.pushState = function(state, title, url) { | |
if (reloadOnNext===true) location.href = url; | |
else pushState.call(this, state, title, url); | |
}; | |
navigator.serviceWorker.controller.addEventListener('statechange', e => { | |
if (e.target.state==='redundant') { | |
reloadOnNext = true; | |
} | |
}); | |
setInterval( () => { | |
navigator.serviceWorker.ready.then( reg => reg.update() ); | |
}, 3e4); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment