In Rails, how can I force update the client's js/css files?

☆樱花仙子☆ 提交于 2019-12-11 15:23:16

问题


When I use javascript_include_tag or stylesheet_link_tag to include files, they have a number at the end to make it easier to circumvent browser caching (update the file without changing the number, the browser still uses the cached version; change the number, the browser will download and use the updated file).

But where does this number come from? When is it updated? And how can I manually update it?

I'm still using Rails 2.3.9, but I guess answers for any version of Rails would be helpful since I couldn't find any.


回答1:


Basically, in Rails 2, the number comes from the file's last modification date, and is added to the link as a query parameter. In Rails 3, it comes from a hash of the file's contents, and is added to the filename itself. The latter should be an improvement - see this page for more on the difference between the two.

Hope that helps!




回答2:


Read http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html



来源:https://stackoverflow.com/questions/11021022/in-rails-how-can-i-force-update-the-clients-js-css-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!