서비스워커 등록 해제

This commit is contained in:
seo
2026-07-22 01:06:29 +09:00
parent cf5fe5b050
commit 07836bad10
3 changed files with 21 additions and 13 deletions
+13 -8
View File
@@ -155,6 +155,18 @@
}).catch(function () {});
}
function unregisterServiceWorkers() {
if (!navigator.serviceWorker || !navigator.serviceWorker.getRegistrations) return Promise.resolve();
return navigator.serviceWorker.getRegistrations().then(function (registrations) {
return Promise.all(registrations.map(function (registration) {
return registration.unregister().catch(function () {});
}));
}).catch(function () {});
}
unregisterServiceWorkers();
function reloadWith(version) {
var token = version.slice(0, 12);
var marker = token + ':' + Math.floor(Date.now() / 10000);
@@ -163,14 +175,7 @@
if (assetTokenFromLocation() && sessionGet(reloadKey) === marker) return;
sessionSet(reloadKey, marker);
withTimeout(deleteCaches(), 2500).then(function () {
if (navigator.serviceWorker && navigator.serviceWorker.getRegistrations) {
navigator.serviceWorker.getRegistrations().then(function (registrations) {
registrations.forEach(function (registration) {
if (registration && typeof registration.update === 'function') registration.update();
});
}).catch(function () {});
}
withTimeout(Promise.all([deleteCaches(), unregisterServiceWorkers()]), 2500).then(function () {
window.location.replace(addQuery(window.location.href, 'assetReload', token));
});
}
+4 -2
View File
@@ -4,8 +4,10 @@
}
window.addEventListener('load', function () {
navigator.serviceWorker.register('/sw.js?v=20260721_nocache1').then(function (registration) {
if (registration && typeof registration.update === 'function') registration.update();
navigator.serviceWorker.getRegistrations().then(function (registrations) {
registrations.forEach(function (registration) {
registration.unregister().catch(function () {});
});
}).catch(function () {});
});
})();