-->

In Rails, how can I force update the client's

2019-09-02 02:33发布

问题:

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