]> git.ardis.lu - ardislu.dev/commitdiff
Avoid caching non-GET request
authorArdis Lu <ardisglu@gmail.com>
Mon, 2 Jan 2023 00:04:56 +0000 (16:04 -0800)
committerArdis Lu <ardisglu@gmail.com>
Mon, 2 Jan 2023 00:04:56 +0000 (16:04 -0800)
sw.js

diff --git a/sw.js b/sw.js
index 94bd6146fe3ab0e68ec5f6bb76752f7595ebf67a..87c02cffdf1a4f2982aac5a619722edce661e919 100644 (file)
--- 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;
This page took 0.040619 seconds and 4 git commands to generate.