(I was going to ask a question about this but eventually pieced together a solution from various doc pages. Since it’s not obvious how to do this I thought I would share the answer.)
- Benefit from CDN performance by caching an html page with CloudFlare, but:
- Don’t allow browsers to cache the page
CloudFlare doesn’t normally cache html responses, which means the response time may be slow as the origin server will be contacted on every request.
It’s not too hard to get CloudFlare to cache HTML in the CDN layer, but without some extra configuration the HTML will be cached by browsers as well (for 4 hours be default). This means that if a user visits your page, and then you update it and they visit it again before their browser cache expires, they will not see the updated page.
So how do you cache a HTML response in CloudFlare but not the browser?