本地缓存文件

This commit is contained in:
SunWuyuan
2025-04-05 09:23:27 +08:00
parent 291c593178
commit 8a1e44f1fa
15 changed files with 612 additions and 49 deletions
+55 -4
View File
@@ -67,8 +67,9 @@ if (!self.define) {
});
};
}
define(['./workbox-86c9b217'], (function (workbox) { 'use strict';
define(['./workbox-5ea419d9'], (function (workbox) { 'use strict';
importScripts("sw-cache-manager.js");
self.skipWaiting();
workbox.clientsClaim();
@@ -81,12 +82,62 @@ define(['./workbox-86c9b217'], (function (workbox) { 'use strict';
"url": "suppress-warnings.js",
"revision": "d41d8cd98f00b204e9800998ecf8427e"
}, {
"url": "index.html",
"revision": "0.6m682f8mvag"
"url": "/",
"revision": "0.0lkakoc2in8"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("/"), {
allowlist: [/^\/$/]
}));
workbox.registerRoute(/\.(?:js)$/i, new workbox.StaleWhileRevalidate({
"cacheName": "js-cache",
plugins: [new workbox.ExpirationPlugin({
maxEntries: 100,
maxAgeSeconds: 604800
})]
}), 'GET');
workbox.registerRoute(/\.(?:css)$/i, new workbox.StaleWhileRevalidate({
"cacheName": "css-cache",
plugins: [new workbox.ExpirationPlugin({
maxEntries: 50,
maxAgeSeconds: 604800
})]
}), 'GET');
workbox.registerRoute(/\.(?:html)$/i, new workbox.NetworkFirst({
"cacheName": "html-cache",
plugins: [new workbox.ExpirationPlugin({
maxEntries: 20,
maxAgeSeconds: 86400
})]
}), 'GET');
workbox.registerRoute(/\.(?:png|jpg|jpeg|svg|gif)$/i, new workbox.StaleWhileRevalidate({
"cacheName": "images-cache",
plugins: [new workbox.ExpirationPlugin({
maxEntries: 50,
maxAgeSeconds: 2592000
})]
}), 'GET');
workbox.registerRoute(/\/cdn-cgi\/.*/i, new workbox.NetworkFirst({
"cacheName": "cdn-cgi-cache",
"networkTimeoutSeconds": 10,
plugins: [new workbox.ExpirationPlugin({
maxEntries: 50,
maxAgeSeconds: 86400
})]
}), 'GET');
workbox.registerRoute(({
url
}) => {
return url.origin !== self.location.origin;
}, new workbox.NetworkFirst({
"cacheName": "external-resources",
"networkTimeoutSeconds": 10,
plugins: [new workbox.ExpirationPlugin({
maxEntries: 100,
maxAgeSeconds: 86400
}), new workbox.CacheableResponsePlugin({
statuses: [0, 200]
})]
}), 'GET');
}));