Rails的3.1在Apache,说的PageSpeed​​"指定缓存验证"使用管道资产Apache的配置时, [英] Rails 3.1 on Apache, PageSpeed says "Specify Cache Validator" when using Asset Pipeline apache config

查看:104
本文介绍了Rails的3.1在Apache,说的PageSpeed​​"指定缓存验证"使用管道资产Apache的配置时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到什么之间的Rails 3.1指南建议,什么谷歌的PageSpeed​​建议缓存的资产管理的冲突。

I am seeing a conflict between what Rails 3.1 guides suggest, and what Google PageSpeed suggest for managing of cached assets.

3.1的Rails导游资产管道提供了一个解决方案,Apache服务器的配置这里

Rails 3.1 guides for asset pipeline offer a solution Apache server configuration here

Apache配置的显着位是:

The salient bit of apache config is:

<LocationMatch "^/assets/.*$">
  # Some browsers still send conditional-GET requests if there's a
  # Last-Modified header or an ETag header even if they haven't
  # reached the expiry date sent in the Expires header.
  Header unset Last-Modified
  Header unset ETag
  FileETag None
  # RFC says only cache for 1 year
  ExpiresActive On
  ExpiresDefault "access plus 1 year"
</LocationMatch>

一切正常,但是当我运行谷歌的PageSpeed​​,它抱怨说我应该指定缓存验证设置为的Last-Modified 的ETag ,列出的所有文件中的资产的文件夹。

Everything works, but when I run Google PageSpeed, it complains that I should "Specify Cache Validator" by setting either Last-Modified or ETag, listing all of the files in the assets folder.

注释掉头取消设置的Last-Modified 满足的PageSpeed​​。

Commenting out the Header unset Last-Modified satisfies PageSpeed.

我做了各种pageloads的快速测试,且至少在Chrome中,它似乎没有有所作为 - 资产缓存无论哪种方式

I did a quick test of the various pageloads, and at least in Chrome, it didn't seem to make a difference -- assets were cached either way.

有谁知道这是适当的?

推荐答案

这code被切断,从原来的Rails的助手code一致性原因粘贴。 (这是我复制​​它)。

That code was cut and pasted from the original Rails helper code for reasons of consistency. (It was me that copied it).

我与史蒂夫Souders的(感谢史蒂夫)这个检查,他说以下内容:

I have checked with Steve Souders (thanks, Steve) on this, and he said the following:

您应该的的取消设置的Last-Modified。我打赌谁写的是点击刷新做他们的测试的人。当你点击刷新你明确告诉浏览器发送一个条件GET。 (请参见

You should not unset Last-Modified. I'm betting the person who wrote that was click "Reload" to do their testing. When you click "Reload" you're explicitly telling the browser to send a conditional GET. (see this)

的ETag有同样的问题(如果你点击刷新,它会发送一个条件GET)。但它有一个不同的问题,这可能意味着你的的取消设置的ETag。问题是,在Apache和IIS默认的ETag语法是导致不必要的验证失败并转移浪费字节。您应该配置语法要解决这些问题,但大多数人觉得它更容易只是没有设置的ETag。 (请参见

ETag has the same issue (if you hit "Reload" it'll send a conditional GET). But it has a different issue that probably means you should unset ETag. The issue is that the default ETag syntax on Apache and IIS is causes unnecessary validation failures and wasted bytes transferred. You should either configure the syntax to workaround these problems, but most people find it easier to just unset ETags. (see this)

我会得到Rails的文档更新!

I'll get the Rails docs updated!

这篇关于Rails的3.1在Apache,说的PageSpeed​​&QUOT;指定缓存验证&QUOT;使用管道资产Apache的配置时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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