There are several similar questions, but none of the ones I've found are clear or definitive.
Here's the behavior I want:
- As long as the network is available, the browser must check if there's a new version
- If there isn't a new version, the browser can use the cached version
- The cached version expires after X days
I think I can do this with Cache-Control: max-age and ETags. However, I can't find whether the max-age should be 0 or how long the content should be cached for.
E.g. if I do Cache-Control: max-age=86400 (1 day) with an ETag, would it:
Make a server request every time, but the server will just return 304 if the ETag didn't change. After 1 day, discard the cached version, and refetch from the server (which should be the same as the discarded version).
Doesn't make any server requests for a day. Then, after 1 day, the server can still return 304. The cached version can stay indefinitely.
I'd like the browser to refetch after X days because in case there's a bug, I don't want users stuck with a broken cached version.