From f3345ad9f89944b2c1fc22733fffcd647b24e7b1 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Tue, 17 Sep 2024 17:35:01 +0800 Subject: [PATCH] Fixes for SW caching --- public/sw.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/public/sw.js b/public/sw.js index 9ab25518..0456a5b7 100644 --- a/public/sw.js +++ b/public/sw.js @@ -16,13 +16,17 @@ const assetsRoute = new Route( ({ request, sameOrigin }) => { const isAsset = request.destination === 'style' || request.destination === 'script'; - const hasHash = /-[0-9a-f]{4,}\./i.test(request.url); + const hasHash = /-[0-9a-z-]{4,}\./i.test(request.url); return sameOrigin && isAsset && hasHash; }, new NetworkFirst({ cacheName: 'assets', networkTimeoutSeconds: 5, plugins: [ + new ExpirationPlugin({ + maxEntries: 30, + purgeOnQuotaError: true, + }), new CacheableResponsePlugin({ statuses: [0, 200], }), @@ -44,7 +48,7 @@ const imageRoute = new Route( cacheName: 'remote-images', plugins: [ new ExpirationPlugin({ - maxEntries: 50, + maxEntries: 30, purgeOnQuotaError: true, }), new CacheableResponsePlugin({ @@ -86,7 +90,7 @@ const apiExtendedRoute = new RegExpRoute( cacheName: 'api-extended', plugins: [ new ExpirationPlugin({ - maxAgeSeconds: 24 * 60 * 60, // 1 day + maxAgeSeconds: 12 * 60 * 60, // 12 hours purgeOnQuotaError: true, }), new CacheableResponsePlugin({ @@ -128,6 +132,7 @@ const apiRoute = new RegExpRoute( networkTimeoutSeconds: 5, plugins: [ new ExpirationPlugin({ + maxEntries: 30, maxAgeSeconds: 5 * 60, // 5 minutes purgeOnQuotaError: true, }),