-
Notifications
You must be signed in to change notification settings - Fork 687
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
Add default caching options when serving with single flag #209
Conversation
Why should we set a different max-age for index.html? 😊 |
Because the vast majority of modern SPAs use a cache busting technique where each bundled JS/CSS has a unique hash (or hash based on content). However cache busting won't work if This allows you, for example, to cache your hashed JS/CSS files for a year but still have the site instantly update when a change is made. |
@ro-savage I thought browsers don't cache HTML files? |
@leo - Nope, browsers will respect cache unless you do a refresh. e.g. press the refresh button, press enter a 2nd time in the url bar, cmd+R) It can be confusing when testing the behaviour, it confused me just now when I was double checking cache behaviour! When you press enter on the URL bar that forces the browser to refresh (and make a request with max-age: 0). So if you make a change, then press 'enter' it will refresh and you will get an uncached copy. But if you just type the URL and go to the site normally, you'll get a cached copy. Heres a quick video example, using now and serve. |
3691032
to
5bb5724
Compare
Looking at this PR, I think we don't have a default caching value anymore? We need that. |
As mentioned in the original comment:
If we need a default, maybe either 0 seconds, aimed as people using serve in development. Or 1 day (or more?) aimed at people using serve in production. 3600ms seems like a strange default to me. But happy to add in 3600ms default if that's what you'd like? |
Thanks for the effort you've put into this PR, but I had to implement a custom solution (the branch had merge conflicts so I thought it would be faster). 🙏 |
Closes #208
For deploys with the
single
flag, it changes thecache-control max-age
to0
forindex.html
, and 1 day for everything else.You can still overwrite the max-age with the
cache
flag, even when deploying withsingle
flag, however it will keep index.html atmax-age 0
I also removed the defaulting of caching being 3600ms (approx 3seconds) as that seemed pointless. Instead just lets micro decide on the default?
This is an alternative to #190. Either works, but would like to see caching done better for SPAs :)