fix: Fetch CORS resources from network #9586
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If we fetch our own assets we want a CORS response to properly cache it in the service worker. If the response is served from the browser cache however, then there is a high chance that the required response headers are missing and the browser responds with a CORS error instead of refetching the resource. This happens because the Vary header does not include headers not present in the original request. To avoid this error, always fetch from the network for requests we intend to cache in the SW.
Demo
https://www.loom.com/share/280ee174d1484814a06e4d2a1c9c2674?sid=374d929f-89ef-4ae5-ad9b-b108e5391737
Testing scenarios
ngrok http 3000
) and configure it in.env
afterwardsyarn predeploy && yarn start
)Final checklist