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

Add default caching options when serving with single flag #209

Closed
wants to merge 2 commits into from

Conversation

ro-savage
Copy link

@ro-savage ro-savage commented May 31, 2017

Closes #208

For deploys with the single flag, it changes the cache-control max-age to 0 for index.html, and 1 day for everything else.

You can still overwrite the max-age with the cache flag, even when deploying with single flag, however it will keep index.html at max-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 :)

@leo
Copy link
Contributor

leo commented Jun 2, 2017

Why should we set a different max-age for index.html? 😊

@ro-savage
Copy link
Author

ro-savage commented Jun 3, 2017

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 index.html is cached because the user will see the old index.html that points to the old bundles.

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.

@leo
Copy link
Contributor

leo commented Jun 3, 2017

@ro-savage I thought browsers don't cache HTML files?

@ro-savage
Copy link
Author

ro-savage commented Jun 3, 2017

@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.
https://www.youtube.com/watch?v=bqwDREbSbdw

@leo
Copy link
Contributor

leo commented Jun 5, 2017

Looking at this PR, I think we don't have a default caching value anymore? We need that.

@ro-savage
Copy link
Author

As mentioned in the original comment:

I also removed the defaulting of caching being 3600ms (approx 3seconds) as that seemed pointless. Instead just lets micro decide on the default?

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?

@leo leo closed this in 6655ed6 Jul 2, 2017
@leo
Copy link
Contributor

leo commented Jul 2, 2017

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). 🙏

@vercel vercel locked and limited conversation to collaborators Jul 2, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants