Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fetch CORS resources from network #9586

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading