在Rails中,如何强制更新客户端的js/css文件? [英] In Rails, how can I force update the client's js/css files?

查看:45
本文介绍了在Rails中,如何强制更新客户端的js/css文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 javascript_include_tag stylesheet_link_tag 包含文件时,它们的末尾都有一个数字,以使其更容易规避浏览器缓存(更新文件而不更改数字),浏览器仍使用缓存的版本;更改编号,浏览器将下载并使用更新的文件.

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?

我仍在使用Rails 2.3.9,但是我猜对于任何版本的Rails的答案都是有用的,因为找不到.

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.

推荐答案

基本上,在Rails 2中,该数字来自文件的上次修改日期,并作为查询参数添加到链接中.在Rails 3中,它来自文件内容的哈希,并添加到文件名本身.后者应该有所改进-请参见此页以获取有关两者之间区别的更多信息.

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.

希望有帮助!

这篇关于在Rails中,如何强制更新客户端的js/css文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆