Skip to content

Instantly share code, notes, and snippets.

@viduraperera
Created May 11, 2022 12:57
Show Gist options
  • Select an option

  • Save viduraperera/eb6d2c6508cfaf087da11eb915218c07 to your computer and use it in GitHub Desktop.

Select an option

Save viduraperera/eb6d2c6508cfaf087da11eb915218c07 to your computer and use it in GitHub Desktop.
const updateServiceWorker = () => {
const registrationWaiting = serviceWorkerRegistration.waiting;
if (registrationWaiting) {
registrationWaiting.postMessage({ type: 'SKIP_WAITING' });
registrationWaiting.addEventListener('statechange', e => {
if (e.target.state === 'activated') {
window.location.reload();
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment