Skip to content

Instantly share code, notes, and snippets.

@developit
Last active September 30, 2020 22:13
Show Gist options
  • Save developit/30a9c97b6b4aeee3afd588af315b154b to your computer and use it in GitHub Desktop.
Save developit/30a9c97b6b4aeee3afd588af315b154b to your computer and use it in GitHub Desktop.
if (typeof window!=='undefined' && navigator.serviceWorker && navigator.serviceWorker.controller) {
let reloadOnNext = false;
let pushState = history.pushState;
history.pushState = function(state, title, url) {
pushState.call(this, state, title, url);
if (reloadOnNext===true) location.reload(true);
};
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