Somebody commented on this question about caching:
...using a Cache-Control value of: max-age=0, s-maxage=604800 seems to get my desired behavior of instant client updates on new page contents, but still caching at the CDN level
Will I really get caching at CDN level and instant updates for my users?
Does it make sense? How does that combination work?
Yes, it makes sense.
With the configuration mentioned in that comment, your users will get
instant
stale responses, so they'll have to verify it the next time they make a resquest. And the CDN will cache a valid response for604800
seconds. So repeated requests will be mostly served by CDN, instead of the Origin server.But what if you update your app? What happens to the stale cache on the CDN?
After a new deployment, you need to make sure all of your stale cache from the CDN will be purged / cleared.
For example, see Purging cached resources from Cloudflare: it gives you numerous options on how to do that.
Firebase Hosting, for example, will clear all CDN cache after a new deployment:
As far as the setting suggested in the comment, I think
Cache-Control: no-cache
would do a better job.From MDN - Cache Control: