From 76d352a666d06d0b303d27953787de820b55d920 Mon Sep 17 00:00:00 2001 From: Yusef Almamari Date: Mon, 15 Jul 2024 23:43:01 +0400 Subject: [PATCH] service-worker.js --- src/service-worker.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/service-worker.js b/src/service-worker.js index 9be60e8..c9a2e6b 100644 --- a/src/service-worker.js +++ b/src/service-worker.js @@ -34,7 +34,11 @@ registerRoute( ); registerRoute( - ({ url }) => url.origin === self.location.origin && url.pathname.endsWith(/\.(png|jpg|jpeg|svg)$/), + ({ url }) => { + const path = url.pathname.split("/"); + const lastSegment = path[path.length - 1]; + return url.origin === self.location.origin && ["png", "jpg", "jpeg", "svg"].includes(lastSegment); + }, new StaleWhileRevalidate({ cacheName: "images", plugins: [new ExpirationPlugin({ maxEntries: 50 })],