From 4b6a707ab7a7d115f914be284a402a04b35d5655 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Tue, 24 Sep 2024 21:15:03 -0700 Subject: [PATCH] Only cache requests on own hostname Otherwise it will try to cache chrome extensions or user-initiated requests from console, which was not intended. --- sw.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sw.js b/sw.js index 1e7c991..1e6463c 100644 --- a/sw.js +++ b/sw.js @@ -1,4 +1,4 @@ -const cacheName = 'v5'; +const cacheName = 'v6'; const cacheChannel = new BroadcastChannel('cache'); async function revalidate(request) { @@ -28,7 +28,7 @@ async function revalidate(request) { // Implements stale-while-revalidate strategy: if there's anything in the cache, return that immediately. // Wait for the origin server's response in parallel and notify cacheChannel if the cache changed. addEventListener('fetch', event => { - if (event.request.method !== 'GET') { + if (event.request.method !== 'GET' || new URL(event.request.url).hostname !== location.hostname) { return; } -- 2.47.3