mirror of https://github.com/Nofated095/blog
update sw.js
This commit is contained in:
parent
98040396bd
commit
ed6e4dce68
|
@ -1,3 +1,3 @@
|
|||
hexo.extend.injector.register('body_end', '<script>window.addEventListener("load",()=>{const e="1699180247";"serviceWorker"in navigator&&localStorage.getItem("sw.js-version")!=e?(navigator.serviceWorker.register("/sw.js",{scope:"/"}).then(function(t){console.log("ServiceWorker registration successful with scope: ",t.scope),localStorage.setItem("sw.js-version",e)}).catch(function(e){console.warn("ServiceWorker registration failed: ",e)}),navigator.serviceWorker.addEventListener("controllerchange",function(){var e=document.querySelector("title");e.innerText="Need update Service Worker - "+e.innerText})):console.log("ServiceWorker already the latest version."),quicklink.listen()})</script>', 'default');
|
||||
hexo.extend.injector.register('body_end', '<script>window.addEventListener("load",()=>{const r="1699180247";"serviceWorker"in navigator&&localStorage.getItem("sw.js-version")!=r?(navigator.serviceWorker.register("/sw.js",{scope:"/"}).then(function(e){console.log("ServiceWorker registration successful with scope: ",e.scope),localStorage.setItem("sw.js-version",r)}).catch(function(e){console.warn("ServiceWorker registration failed: ",e)}),navigator.serviceWorker.addEventListener("controllerchange",function(){var e=document.querySelector("title");e.innerText="Need update Service Worker - "+e.innerText})):console.log("ServiceWorker already the latest version."),quicklink.listen()})</script>', 'default');
|
||||
|
||||
hexo.extend.injector.register('body_end', '<script async src="/js/quicklink.js"></script>', 'default');
|
||||
|
|
40
source/sw.js
40
source/sw.js
|
@ -9,7 +9,7 @@ const { CacheFirst, NetworkFirst, NetworkOnly, StaleWhileRevalidate } = strategi
|
|||
const { ExpirationPlugin } = expiration;
|
||||
const { CacheableResponsePlugin } = cacheableResponse;
|
||||
|
||||
const cacheSuffixVersion = '-231126a',
|
||||
const cacheSuffixVersion = '-231130a',
|
||||
// precacheCacheName = core.cacheNames.precache,
|
||||
// runtimeCacheName = core.cacheNames.runtime,
|
||||
maxEntries = 100;
|
||||
|
@ -36,23 +36,6 @@ core.skipWaiting();
|
|||
core.clientsClaim();
|
||||
precaching.cleanupOutdatedCaches();
|
||||
|
||||
routing.registerRoute(
|
||||
/.*lf3-cdn-tos\.bytecdntp\.com/,
|
||||
new CacheFirst({
|
||||
cacheName: 'static-immutable' + cacheSuffixVersion,
|
||||
fetchOptions: {
|
||||
mode: 'cors',
|
||||
credentials: 'omit'
|
||||
},
|
||||
plugins: [
|
||||
new ExpirationPlugin({
|
||||
maxAgeSeconds: 30 * 24 * 60 * 60,
|
||||
purgeOnQuotaError: true
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
|
||||
routing.registerRoute(
|
||||
/.*xgjalbum\.oss-cn-hangzhou\.aliyuncs\.com/,
|
||||
new CacheFirst({
|
||||
|
@ -104,23 +87,6 @@ routing.registerRoute(
|
|||
})
|
||||
);
|
||||
|
||||
routing.registerRoute(
|
||||
/.*comment\.9595095\.xyz/,
|
||||
new CacheFirst({
|
||||
cacheName: 'static-immutable' + cacheSuffixVersion,
|
||||
fetchOptions: {
|
||||
mode: 'cors',
|
||||
credentials: 'omit'
|
||||
},
|
||||
plugins: [
|
||||
new ExpirationPlugin({
|
||||
maxAgeSeconds: 30 * 24 * 60 * 60,
|
||||
purgeOnQuotaError: true
|
||||
})
|
||||
]
|
||||
})
|
||||
);
|
||||
|
||||
routing.registerRoute(
|
||||
/.*cdn\.jsdelivr\.net/,
|
||||
new CacheFirst({
|
||||
|
@ -233,8 +199,8 @@ routing.registerRoute(
|
|||
);
|
||||
|
||||
routing.registerRoute(
|
||||
// Cache CSS files
|
||||
/.*\.(json)/,
|
||||
// Cache fonts files
|
||||
/.*\.(woff2|woff)/,
|
||||
// Use cache but update in the background ASAP
|
||||
StaleWhileRevalidateInstance
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue