From 9adb1092668ecec0cfb0418270be787ae5f4b87a Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sun, 1 Jan 2023 16:04:56 -0800 Subject: [PATCH] Avoid caching non-GET request --- sw.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sw.js b/sw.js index 94bd614..87c02cf 100644 --- a/sw.js +++ b/sw.js @@ -1,4 +1,4 @@ -const cacheName = 'v4'; +const cacheName = 'v5'; const cacheChannel = new BroadcastChannel('cache'); async function revalidate(request) { @@ -28,6 +28,10 @@ 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. globalThis.addEventListener('fetch', event => { + if (event.request.method !== 'GET') { + return; + } + event.respondWith(caches.match(event.request).then(cacheResponse => { const originResponse = revalidate(event.request); return cacheResponse === undefined ? originResponse : cacheResponse; -- 2.47.3