Skip to content

Commit 976231b

Browse files
Shen-wbKeillion
andauthored
Authorization requests should not be cached (#196)
* Authorization requests should not be cached * move condition position --------- Co-authored-by: Keillion <[email protected]>
1 parent 6f7dcef commit 976231b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

hello-world/pwa/service-worker.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,18 @@ self.addEventListener("fetch", (e) => {
5959

6060
// Otherwise, fetch from network
6161
const response = await fetch(e.request);
62-
const cache = await caches.open(cacheName);
63-
console.log(`[Service Worker] Caching new resource: ${e.request.url}`);
64-
if (e.request.method !== "POST") {
62+
63+
if(
64+
e.request.method !== "POST" &&
65+
// Authorization requests should not be cached
66+
!/https:\/\/.*?\.dynamsoft.com\/auth/.test(e.request.url)
67+
// You can add other filter conditions
68+
){
69+
const cache = await caches.open(cacheName);
70+
console.log(`[Service Worker] Caching new resource: ${e.request.url}`);
6571
cache.put(e.request, response.clone());
6672
}
73+
6774
return response;
6875
})()
6976
);

0 commit comments

Comments
 (0)