chore: remove locale files from service worker cache

This commit is contained in:
Tristan Yang
2023-01-17 09:36:48 +08:00
parent ee9a4f23ad
commit dea3dc5508
+7 -15
View File
@@ -32,12 +32,16 @@ registerRoute(
if (request.mode !== "navigate") { if (request.mode !== "navigate") {
return false; return false;
} // If this is a URL that starts with /_, skip. } // If this is a URL that starts with /_, skip.
const urlPath = url.pathname;
if (url.pathname.startsWith("/_") || url.pathname.startsWith("/api/swagger")) { // 忽略swagger文档 与 本地语言文件
if (urlPath.startsWith("/api/swagger") || urlPath.startsWith("/locales/")) {
return false;
}
if (urlPath.startsWith("/_")) {
return false; return false;
} // If this looks like a URL for a resource, because it contains // a file extension, skip. } // If this looks like a URL for a resource, because it contains // a file extension, skip.
if (url.pathname.match(fileExtensionRegexp)) { if (urlPath.match(fileExtensionRegexp)) {
return false; return false;
} // Return true to signal that we want to use the handler. } // Return true to signal that we want to use the handler.
@@ -61,18 +65,6 @@ registerRoute(
] ]
}) })
); );
// 缓存多语言文件
registerRoute(
({ url }) => url.pathname.startsWith("/locales/"),
new StaleWhileRevalidate({
cacheName: "locales",
plugins: [
// Ensure that once this runtime cache reaches a maximum size the
// least-recently used images are removed.
new ExpirationPlugin({ maxEntries: 100, maxAgeSeconds: 5 * 60 })
]
})
);
// This allows the web app to trigger skipWaiting via // This allows the web app to trigger skipWaiting via
// registration.waiting.postMessage({type: 'SKIP_WAITING'}) // registration.waiting.postMessage({type: 'SKIP_WAITING'})