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

automatically cache busting the json files based on the hash in meta tag #1648

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

atflick
Copy link

@atflick atflick commented Aug 19, 2022

Problem: json files get cached and when they are fetched their hash doesn't match the hash that gridsome generated in the HTML that's fetching the json files. This results in the Hash did not match error which then breaks all pages until the user clears their cache.

This change simply adds the matching hash as a query param when the json files are fetched, meaning they can still be cached until that hash changes in which they should be freshly fetched.

This is the hash being added in the network tab:
image

@atflick atflick changed the title automatically cache busting the json files based on the has in meta tag automatically cache busting the json files based on the hash in meta tag Aug 19, 2022
@atflick atflick mentioned this pull request Aug 19, 2022
@atflick
Copy link
Author

atflick commented Aug 19, 2022

Solves this issue: #1032

@ai-slave
Copy link

@hjvedvik can you please merge this one?

@atflick
Copy link
Author

atflick commented Dec 16, 2022

bumping this again @hjvedvik

This would greatly increase the confidence I have when deploying new changes to our public site. We recently had a situation where there were a bunch of updates made to our site that got deployed earlier than we wanted and we rolled them back quickly but the json files were getting cached on the client side which was completely breaking the site for any users who had visited the newly updated version, then the rolled back version. Similar situation happens on consecutive quick changes/updates

@atflick
Copy link
Author

atflick commented Jun 29, 2023

@hjvedvik bumping this again, this simple change would help anyone still using gridsome out A LOT.

@sergeyfilimonov
Copy link
Member

sergeyfilimonov commented Aug 28, 2023

@atflick how is this code working? there is no hash variable defined in the file so the build goes hash is undefined. So for now I've just changed /index.json in the file to /index.json?h=Math.floor(Math.random() * 1000000000000000)

@atflick
Copy link
Author

atflick commented Aug 29, 2023

@sergeyfilimonov That works too, but the hash variable should be getting defined just above on line 57. Maybe it doesn't get defined in certain situations. It's been a while since I looked at this.

image

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.

None yet

3 participants