From: Ardis Lu Date: Wed, 25 Sep 2024 04:15:03 +0000 (-0700) Subject: Only cache requests on own hostname X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=4b6a707ab7a7d115f914be284a402a04b35d5655;p=ardislu.dev Only cache requests on own hostname Otherwise it will try to cache chrome extensions or user-initiated requests from console, which was not intended. --- 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; }