How to make sure clients update their browser cache when my website is updated?
Posted
by
user64204
on Server Fault
See other posts from Server Fault
or by user64204
Published on 2012-06-20T20:11:07Z
Indexed on
2012/06/20
21:17 UTC
Read the original article
Hit count: 198
I am using the HTTP 1.1
Cache-Control
header to implement client-side caching. Since I update my website only once a month I would like the CSS
and JS
files to be cached for 30 days with Cache-Control: max-age=2592000
. The problem is that the 30-day period defined by Cache-Control
doesn't coincide with the website update cycle, it starts from the moment the users visit the site and ends 30 days later, which means an update could occur in the meantime and users would be running with outdated content for a while, which could break the rendering of the website if for instance the HTML
and CSS
no longer match.
How can I perform client-side caching of content for periods of several days but somehow get users to refresh their CSS/JS
files after the website has been updated?
One solution I could think of is that if website updates can be schedule, the max-age
returned by the server could be decreased every day accordingly so that no matter when people visit the website, the end of caching period would coincide with the update of the website, but changing the server configuration every day goes against one of my sysadmin principles (once it's running, don't touch it).
© Server Fault or respective owner