diff --git a/3dtank.com/play/static/js/main.9f4e7a89.js b/3dtank.com/play/static/js/main.9f4e7a89.js index ad6f3eb..25a390d 100644 --- a/3dtank.com/play/static/js/main.9f4e7a89.js +++ b/3dtank.com/play/static/js/main.9f4e7a89.js @@ -131,13 +131,7 @@ var __webpack_modules__ = window.__modules__; // 作用域必须是 /:首页 / 发起的 /play/... 请求才会被接管(serve.js 已放行 Service-Worker-Allowed) // 用途:把 unpacked 下的散装小文件用单包就地命中(hornet_sw.js 内置单包缓存) if ('serviceWorker' in navigator && /^(localhost|127\.0\.0\.1|\[::1\])$/.test(location.hostname)) { - if (/#nosw/.test(location.hash)) { - // #nosw:注销已注册的 Service Worker(清除单包缓存接管),用于排查镜像页问题;生效需再刷新一次 - navigator.serviceWorker.getRegistrations().then(function (Regs) { - Regs.forEach(function (Reg) { Reg.unregister(); }); - console.warn('[Hornet] #nosw:已注销 Service Worker(再刷新一次生效)'); - }); - } else { + if (/#sw\b/.test(location.hash) && !/#nosw/.test(location.hash)) { navigator.serviceWorker .register('/hornet_sw.js', { scope: '/', updateViaCache: 'none' }) .then(function (Reg) { @@ -147,6 +141,13 @@ var __webpack_modules__ = window.__modules__; .catch(function (Err) { console.warn('[Hornet] Service Worker 注册失败: ' + (Err && Err.message)); }); + } else { + // 默认**不启用** Service Worker:注销已注册的实例(清除单包缓存接管),排查镜像页问题时用;生效需再刷新一次 + navigator.serviceWorker.getRegistrations().then(function (Regs) { + if (!Regs.length) return; + Regs.forEach(function (Reg) { Reg.unregister(); }); + console.warn('[Hornet] Service Worker 已注销(默认关闭;要启用请在 URL 加 #sw,需再刷新一次)'); + }); } } diff --git a/tools/split.js b/tools/split.js index 6f4bb43..20de2cd 100644 --- a/tools/split.js +++ b/tools/split.js @@ -365,13 +365,7 @@ var __webpack_modules__ = window.__modules__; // 作用域必须是 /:首页 / 发起的 /play/... 请求才会被接管(serve.js 放行 Service-Worker-Allowed) // 用途:把 unpacked 下的散装小文件用单包就地命中(hornet_sw.js 内置单包缓存) if ('serviceWorker' in navigator && /^(localhost|127\\.0\\.0\\.1|\\[::1\\])$/.test(location.hostname)) { - if (/#nosw/.test(location.hash)) { - // #nosw:注销已注册的 Service Worker(清除单包缓存接管),用于排查镜像页问题;生效需再刷新一次 - navigator.serviceWorker.getRegistrations().then(function (Regs) { - Regs.forEach(function (Reg) { Reg.unregister(); }); - console.warn('[Hornet] #nosw:已注销 Service Worker(再刷新一次生效)'); - }); - } else { + if (/#sw\\b/.test(location.hash) && !/#nosw/.test(location.hash)) { navigator.serviceWorker .register('/hornet_sw.js', { scope: '/', updateViaCache: 'none' }) .then(function (Reg) { @@ -381,6 +375,13 @@ var __webpack_modules__ = window.__modules__; .catch(function (Err) { console.warn('[Hornet] Service Worker 注册失败: ' + (Err && Err.message)); }); + } else { + // 默认**不启用** Service Worker:注销已注册的实例(清除单包缓存接管),排查镜像页问题时用;生效需再刷新一次 + navigator.serviceWorker.getRegistrations().then(function (Regs) { + if (!Regs.length) return; + Regs.forEach(function (Reg) { Reg.unregister(); }); + console.warn('[Hornet] Service Worker 已注销(默认关闭;要启用请在 URL 加 #sw,需再刷新一次)'); + }); } }