From dfb42089848e37e7512f1ebdba9edf36a367ae5f Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Tue, 29 Nov 2022 23:14:03 +0800 Subject: [PATCH] chore: pre cache locales --- src/service-worker.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/service-worker.ts b/src/service-worker.ts index 9637a607..6745a589 100644 --- a/src/service-worker.ts +++ b/src/service-worker.ts @@ -61,6 +61,18 @@ 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 }) + ] + }) +); // This allows the web app to trigger skipWaiting via // registration.waiting.postMessage({type: 'SKIP_WAITING'})