From a393cd4df0f792b7357a086da38e494ba2f6eaaa Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Tue, 2 Jul 2024 16:23:31 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(service-worker)=20external?= =?UTF-8?q?=20url=20NetworkFirst?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We will use the NetworkFirst strategy for external URLs, if a patch is made from the external resource, the resource will be updated directly. --- .../features/service-worker/service-worker.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/frontend/apps/impress/src/features/service-worker/service-worker.ts b/src/frontend/apps/impress/src/features/service-worker/service-worker.ts index a3c30768..e542cb18 100644 --- a/src/frontend/apps/impress/src/features/service-worker/service-worker.ts +++ b/src/frontend/apps/impress/src/features/service-worker/service-worker.ts @@ -130,6 +130,23 @@ setCatchHandler(async ({ request, url, event }) => { } }); +/** + * External urls cache strategy + */ +registerRoute( + ({ url }) => !url.href.includes(self.location.origin), + new NetworkFirst({ + cacheName: getCacheNameVersion('default-external'), + plugins: [ + new CacheableResponsePlugin({ statuses: [0, 200] }), + new ExpirationPlugin({ + maxAgeSeconds: 24 * 60 * 60 * DAYS_EXP, + }), + ], + }), + 'GET', +); + /** * Cache stategy static files images (images / svg) */