问题
I'm interested how people deal with updating images/css/js with regards to the the browser cache.
It's obviously good to use mod_expires and have a future expiry etc - but how can you then update those files if you don't want to rename the file all the time?
Does anyone have any cool tricks with a version number which will not risk the browser (or proxy) not wanting to cache the file, but will still guarantee the user will see the new version if it's updated?
回答1:
The general way of doing this is generating a random number and adding it as a GET/POST variable. For example:
http://example.com/myfile.html?r=189818273
Just my two cents....
回答2:
All these resources will be updated if you won't change default caching rules. You can use FireBUG for testing. It will return 304 if resource is not modified and 200 if it was modified. So if you have image on the page it will be checked in every request by default.
回答3:
I would add a query string parameter with the timestamp of the last file modification:
http://example.com/script.js?v=123456
Alternatively, you can define a global variable in your application and use it as timestamp. When you change one of the files, just increment that variable. That means that all your resources will be invalidated at the same time, but that may be a simpler solution than reading the timestamp of the file.
来源:https://stackoverflow.com/questions/4817714/updating-cached-images-css-js-without-renaming