Skip to content

Commit

Permalink
fix: fetch in service worker only for '/' and '.js' suffixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheraff committed Oct 4, 2024
1 parent 599fad2 commit 766799d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions public/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ s.addEventListener("install", (event) => event.waitUntil(s.skipWaiting()))
s.addEventListener("activate", (event) => event.waitUntil(s.clients.claim()))

s.addEventListener("fetch", (event) => {
if (event.request.cache === "only-if-cached" && event.request.mode !== "same-origin") {
if (event.request.cache === "only-if-cached" && event.request.mode !== "same-origin")
return
}
if (!event.request.url.endsWith('/') && !event.request.url.endsWith('.js'))
return

event.respondWith(
fetch(event.request)
.then((response) => {
Expand Down

0 comments on commit 766799d

Please sign in to comment.