浏览 1067 次
|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
最后更新时间:2007-10-12
<% image_tag 'rails.png' %> 会生成如下html <img alt="xxx" src="/images/rails.png?1190614494" /> javascript_include_tag 和 stylesheet_link_tag 也是如此,如何能去掉这些时间戳呢? 声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
最后更新时间:2007-10-12
自动添加时间戳是一个很酷的功能,干嘛要去掉?
用户的浏览器会在本地缓存你网站的CSS文件,如果你的网站更新了网页结构和CSS,浏览器只知道更新动态页面,却根本不知道要去重新加载CSS,结果你的用户就会看到页面布局一塌糊涂,就会骂街。是不是很悲惨? rails给CSS添加时间戳,浏览器就可以知道缓存在本地的CSS究竟又没有过期,如果过期,那么重新加载一遍吧,这样就避免了这个讨厌的问题啦。 |
|
| 返回顶楼 | |
|
最后更新时间:2007-10-12
是啊,去掉干什么,好不容易加上的
|
|
| 返回顶楼 | |
|
最后更新时间:2007-10-13
粗略看了下, 感觉设置 ENV["RAILS_ASSET_ID"] 这个环境变量为空, 就可以忽略掉这个功能了.
|
|
| 返回顶楼 | |
|
最后更新时间:2007-10-14
有时候是需要去掉的。
因为带参数调用的url按规定浏览器是不会缓存的(但是IE实际上做了缓存,BS下微软),所以如果想所有浏览器对内容缓存,最好不要写成带参数的形式。 其实可以写成加 _<version>的形式,比如/js/a.js 写成 /js/a_05.js 然后通过 urlrewrite 机制让实际访问的文件是/js/a.js 这样版本控制和全部缓存的目的都可以达到, 这个时候可以把 js和cs设置为永久缓存。 |
|
| 返回顶楼 | |
|
最后更新时间:2007-10-14
vincent253 写道 有时候是需要去掉的。
因为带参数调用的url按规定浏览器是不会缓存的(但是IE实际上做了缓存,BS下微软),所以如果想所有浏览器对内容缓存,最好不要写成带参数的形式。 其实可以写成加 _<version>的形式,比如/js/a.js 写成 /js/a_05.js 然后通过 urlrewrite 机制让实际访问的文件是/js/a.js 这样版本控制和全部缓存的目的都可以达到, 这个时候可以把 js和cs设置为永久缓存。 经过实践测试,IE6,FireFox2.0,Opera9.2全部可以缓存带参数的静态资源,如果你不信,你可以试试看你访问JavaEye网站以后,你浏览器本地有没有缓存CSS和JS。不知道你说的“规定”出自何处? |
|
| 返回顶楼 | |
|
最后更新时间:2007-10-14
robbin 写道 经过实践测试,IE6,FireFox2.0,Opera9.2全部可以缓存带参数的静态资源,如果你不信,你可以试试看你访问JavaEye网站以后,你浏览器本地有没有缓存CSS和JS。不知道你说的“规定”出自何处? 我是从下面这段文字了解到这点的: "According the letter of the HTTP caching specification, user agents should never cache URLs with query strings. While Internet Explorer and Firefox ignore this, Opera and Safari don’t - to make sure all user agents can cache your resources, we need to keep query strings out of their URLs." Cal Henderson, http://www.thinkvitamin.com/features/webapps/serving-javascript-fast, May 21, 2006 查了下 RFC2616 Hypertext Transfer Protocol -- HTTP/1.1 13.9 Side Effects of GET and HEAD Unless the origin server explicitly prohibits the caching of their responses, the application of GET and HEAD methods to any resources SHOULD NOT have side effects that would lead to erroneous behavior if these responses are taken from a cache. They MAY still have side effects, but a cache is not required to consider such side effects in its caching decisions. Caches are always expected to observe an origin server's explicit restrictions on caching. We note one exception to this rule: since some applications have traditionally used GETs and HEADs with query URLs (those containing a "?" in the rel_path part) to perform operations with significant side effects, caches MUST NOT treat responses to such URIs as fresh unless the server provides an explicit expiration time. This specifically means that responses from HTTP/1.0 servers for such URIs SHOULD NOT be taken from a cache. See section 9.1.1 for related information. 当然可能现在的浏览器都学IE了。 |
|
| 返回顶楼 | |








