Skip to content

Commit

Permalink
fix: Fetch CORS resources from network (#9586)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dschoordsch authored Apr 2, 2024
1 parent 341b4b7 commit b6ddfa5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/client/serviceWorker/sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ const onFetch = async (event: FetchEvent) => {
// request.mode could be 'no-cors'
// By fetching the URL without specifying the mode the response will not be opaque
const isParabolHosted = url.startsWith(PUBLIC_PATH) || url.startsWith(self.origin)
const req = isParabolHosted ? request.url : request
const networkRes = await fetch(req)
// if one of our assets is not in the service worker cache, then it's either fetched via network or served from the broswer cache.
// The browser cache most likely has incorrect CORS headers set, so we better always fetch from the network.
const req = isParabolHosted ? fetch(request.url, {cache: 'no-store'}) : fetch(request)
const networkRes = await req
const cache = await caches.open(DYNAMIC_CACHE)
// cloning here because I'm not sure if we must clone before reading the body
cache.put(request.url, networkRes.clone()).catch(console.error)
Expand Down

0 comments on commit b6ddfa5

Please sign in to comment.