Firefox决定不缓存什么? [英] what does firefox decide not to cache?

查看:87
本文介绍了Firefox决定不缓存什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebug查看来自Rails应用程序的网络流量,并且发现没有缓存CSS和javascript文件。在页面中,类似以下内容:

I'm viewing the network traffic from my rails application using firebug and I see that the css and javascript files are not being cached. In the page, are things like:

<script src="/javascripts/prototype.js?1315256241" type="text/javascript"></script>

,看起来好像?1315256241导致FF不缓存该项目。但是1315256241是几年前推出的Rails的功能。因此,令我感到惊讶的是,它阻止了该项目被缓存,但没人问过或修复它。

and it appears as if the ?1315256241 causes FF to not cache the item. But the ?1315256241 is a "feature" of Rails that was introduced a few years back. So I'm surprised that it prevents the item from being cached yet no one has asked about it or fixed it.

我曾在FF论坛上问过同样的问题甚至在Rails论坛中都无济于事。似乎没有人理解我的问题或观点。所以我想我应该在这里尝试。

I've ask this same question on the FF forum and maybe in the Rails forum to no avail. No one seems to understand my question or the point of it. So I thought I would try here.

我的问题是?1315256241后缀(查询)是否阻止FF缓存页面?

My question is "does the ?1315256241 suffix (the query) prevent FF from caching the page?"

如果这样做,大多数人会在Rails中做什么以防止这种情况发生?

And if it does, what do most people do in Rails to prevent that?

推荐答案

如果您查看 AssetTagHelper 的文档,然后查找自定义资产路径,您将找到有关为什么代码会添加时间戳以及对我的Apache配置进行必要更改以利用此功能的解释。

If you view the documentation for the AssetTagHelper and look for "Customizing the asset path" you will find this explanation of why the code adds the timestamp along with the needed changes to my Apache configuration to take advantage of this feature.


默认情况下,Rails将资产的时间戳附加到所有资产路径。这样,您就可以为该资产设置一个很长的过期日期,但是仍然可以通过简单地更新文件(并因此更新时间戳,然后更新URL来立即使它失效),因为时间戳是其中的一部分,这反过来破坏了缓存)。

By default, Rails appends asset’s timestamps to all asset paths. This allows you to set a cache-expiration date for the asset far into the future, but still be able to instantly invalidate it by simply updating the file (and hence updating the timestamp, which then updates the URL as the timestamp is part of that, which in turn busts the cache).

这是Web服务器的职责,您需要利用该服务器设置缓存资产的远期到期日期此功能。这是Apache的示例:

It’s the responsibility of the web server you use to set the far-future expiration date on cache assets that you need to take advantage of this feature. Here’s an example for Apache:



# Asset Expiration
ExpiresActive On
<FilesMatch "\.(ico|gif|jpe?g|png|js|css)$">
  ExpiresDefault "access plus 1 year"
</FilesMatch>

(文档仍在继续...)

(and the documentation continues...)

这篇关于Firefox决定不缓存什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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