更新serviceworker逻辑

This commit is contained in:
lloydzhou
2024-07-16 16:37:55 +08:00
parent 4b84fb328c
commit eb7c7cdcb6
2 changed files with 9 additions and 1 deletions

View File

@@ -2,8 +2,15 @@ if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('/serviceWorker.js').then(function (registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
registration.update().then(res => {
console.log('ServiceWorker registration update: ', res);
});
}, function (err) {
console.error('ServiceWorker registration failed: ', err);
});
navigator.serviceWorker.addEventListener('controllerchange', function() {
console.log('ServiceWorker controllerchange ');
window.location.reload(true);
});
});
}
}