开发者

Updating cached images/css/js without renaming

开发者 https://www.devze.com 2023-02-07 05:28 出处:网络
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 t

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开发者_JS百科 the new version if it's updated?


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....


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消