<script>
window.isUpdateAvailable = new Promise(function(resolve, reject) {
navigator.serviceWorker.register('sw.js')
.then(reg => {
reg.onupdatefound = () => {
const installingWorker = reg.installing;
installingWorker.onstatechange = () => {
switch (installingWorker.state) {
case 'installed':
if (navigator.serviceWorker.controller) {
resolve(true);
} else {
// no update available
resolve(false);
}
break;
}
}
}
})
.catch(err => console.error('[SW ERROR]', err));
});
</script>
You'll need to replace 'sw.js' with the name of your service worker file.
Comments