-
-
Save AnthoniG/1a257ef08d502e794b09c12c7b618f4d to your computer and use it in GitHub Desktop.
Function to unregister SW and clear out old caches.
This file contains hidden or 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
window.__testCleanup = () => { | |
const unregisterSW = () => { | |
return navigator.serviceWorker.getRegistrations() | |
.then((registrations) => { | |
const unregisterPromise = registrations.map((registration) => { | |
return registration.unregister(); | |
}); | |
return Promise.all(unregisterPromise); | |
}); | |
}; | |
const clearCaches = () => { | |
return window.caches.keys() | |
.then((cacheNames) => { | |
return Promise.all(cacheNames.map((cacheName) => { | |
return window.caches.delete(cacheName); | |
})); | |
}); | |
}; | |
return Promise.all([ | |
unregisterSW(), | |
clearCaches(), | |
]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment