From dea3dc550870d513620d332180c0973618f244c5 Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Tue, 17 Jan 2023 09:36:48 +0800 Subject: [PATCH] chore: remove locale files from service worker cache --- src/service-worker.ts | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/service-worker.ts b/src/service-worker.ts index 546cc28b..c4b2c6ee 100644 --- a/src/service-worker.ts +++ b/src/service-worker.ts @@ -32,12 +32,16 @@ registerRoute( if (request.mode !== "navigate") { return false; } // If this is a URL that starts with /_, skip. - - if (url.pathname.startsWith("/_") || url.pathname.startsWith("/api/swagger")) { + const urlPath = url.pathname; + // 忽略swagger文档 与 本地语言文件 + if (urlPath.startsWith("/api/swagger") || urlPath.startsWith("/locales/")) { + return false; + } + if (urlPath.startsWith("/_")) { return false; } // 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 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 // registration.waiting.postMessage({type: 'SKIP_WAITING'})