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

Feat: Fix error when user navigates after a deployment #194

Merged
merged 2 commits into from
Apr 8, 2024

Conversation

bsokol-wl
Copy link
Contributor

If a user is on the site when a deployment happens, they will get an error if they try to load a chunk (navigate to a route) that hadn't previously been fetched. This is because index.html hasn't been refreshed, and will attempt to fetch a chunk that no longer exists. This change will allow the user to fetch the new chunk immediately, or continue using the old chunk (if it has been cached in the browser) until they refresh. Refreshing will fetch all chunks again as needed.

The behavior is due to the hash inserted into the file name, causing the file name to change on every deployment. My tests show that this cache-busting hash isn't necessary. I tested the solution with basic default cache control headers (max age=60 minutes) as well as directly on Netlify (max age=0 minutes, force revalidate). If the file changes, the CDN will respond with the updated copy, even if the file name is the same and even if you are below the max-age. If it hasn't changed, the CDN sends a 304 and the browser uses its cached version.

@patricklafrance
Copy link
Member

LGTM, let me know when the CI is fixed so I can approve.

@bsokol-wl bsokol-wl merged commit d2e7499 into main Apr 8, 2024
1 check passed
@bsokol-wl bsokol-wl deleted the feat/webpack-remove-file-hash branch April 8, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants