I don’t know much about how caching works, or much control over my hosting’s nginx server. However, I do have a live site that I need to make a change to, so your advice will be very much appreciated.
Currently I have the following three files:
index.html
my.js
my.css
All the files are being served (on my browser) with the following headers:
Date:Wed, 22 Feb 2012 23:17:49 GMT
ETag:"b2c84d1-7551-4b995b0c89c0"
Last-Modified:Wed, 22 Feb 2012 23:14:34 GMT
Server:nginx
There aren’t any other cache-related headers. Given the above, if I simply replace the files with new versions, can I assume that users’ browsers will know not to use cached versions? (I assume if I replace the file, the ETag will change.)
What I’d like to avoid is a situation where a user’s browser downloads the new version of index.html but continues to refer to a cached version of my.js, because that’s likely to break things. I’d also like to know if I can rely on the users seeing the newer version of the site, or if some users will continue to see a cached version.
Thanks for your help.
The browser will send the
If-Modified-Since:and (if you have a recent browser) theIf-None-Match:headers, the first refering to theLast-Modified:header, the latter containing theETag. The server will send the new file, if the modification date is newer than the Last-Modified header. How the ETag changes will depend on your server, but in most cases this will be a hash over the file content.So just make sure that both the file content changes and the modification date is up-to-date (e.g. by
touch /var/www/your-file.js).