我有我的服务器上安装的Apache 2.2.11,我一直试图减less我的网站页面的加载时间基于yslow firefox插件的build议。
我已经configuration了gzip和etag以及其他一些其他的build议,但是我注意到在我的css文件的头文件中,etag被添加了文本gzip。
有谁知道为什么以及如何绕过这个?
从我的服务器头 date星期日,07六月2009 10:40:57 GMT 服务器Apache / 2.2.11(Fedora) Last-Modified Sun,2009年5月31日15:06:38 GMT Etag“3b4-46b36a802bb80”-gzip 接受范围字节 高速caching控制最大年龄= 2592000 到期星期二,07七月2009 10:40:57 GMT 不同的接受编码 内容编码gzip 内容长度530 连接closures 内容types文本/ CSS
我的托pipe软件包上的相同代码使用旧版本的Apache,并没有相同的问题。 难道这只是一个Apache的错误?
从我的托pipe包头 date星期日,07六月2009 10:48:26 GMT 服务器Apache / 2.0.63(FreeBSD)mod_python / 3.3.1 Python / 2.5.1带有Suhosin-Patch的PHP / 5.2.6 mod_fastcgi / 2.4.6 mod_ssl / 2.0.63 OpenSSL / 0.9.7e-p1 DAV / 2 mod_perl / 2.0.4 Perl / v5.8.8 Last-Modified星期六,21二月2009 13:54:52 GMT Etag“3b4-1d104300” 接受范围字节 高速caching控制最大年龄= 2592000 到期星期二,07七月2009 10:48:26 GMT 不同的接受编码 内容编码gzip 内容长度530 连接closures 内容types文本/ CSS
这是一个理想的.htaccess压缩和设置sutiable过期头。
# Insert filter SetOutputFilter DEFLATE # Netscape 4.x has some problems... BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems BrowserMatch ^Mozilla/4\.0[678] no-gzip # MSIE masquerades as Netscape, but it is fine # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-vary <IfModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 seconds" ExpiresByType image/x-icon "access plus 2592000 seconds" ExpiresByType image/jpeg "access plus 2592000 seconds" ExpiresByType image/png "access plus 2592000 seconds" ExpiresByType image/gif "access plus 2592000 seconds" ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds" ExpiresByType text/css "access plus 604800 seconds" ExpiresByType text/javascript "access plus 216000 seconds" ExpiresByType application/x-javascript "access plus 216000 seconds" ExpiresByType text/html "access plus 600 seconds" ExpiresByType application/xhtml+xml "access plus 600 seconds" </IfModule> <IfModule mod_headers.c> <FilesMatch "\\.(ico|jpe?g|png|gif|swf)$"> Header set Cache-Control "max-age=2592000, public" </FilesMatch> <FilesMatch "\\.(css)$"> Header set Cache-Control "max-age=604800, public" </FilesMatch> <FilesMatch "\\.(js)$"> Header set Cache-Control "max-age=216000, private" </FilesMatch> <FilesMatch "\\.(x?html?|php)$"> Header set Cache-Control "max-age=600, private, must-revalidate" </FilesMatch> </IfModule> <IfModule mod_headers.c> Header unset ETag </IfModule> FileETag None <IfModule mod_headers.c> Header unset Last-Modified </IfModule>
下面的文章介绍了它的function,并讨论了压缩:
http://www.samaxes.com/2009/01/06/more-on-compressing-and-caching-your-site-with-htaccess/
希望有所帮助。
Apache mod_deflate正在为每个实体创build唯一的Etag,因为这些标识了URL的特定实体变体。 每个谈判的变体需要独特的ETag:s。 对于mod_deflate ,只需将编码添加到已经计算好的ETag即可。
一个解决方法是从Etag中删除编码:
<Location /js> RequestHeader edit "If-None-Match" "^(.*)-gzip$" "$1" Header edit "ETag" "^(.*[^g][^z][^i][^p])$" "$1-gzip" </Location>
如果您正在使用mod_deflate模块的Apache 2.5,则可以使用指令DeflateAlterETag指定在压缩响应时如何更改ETag哈德键。
DeflateAlterETag AddSuffix|NoChange|Remove
来源: https : //httpd.apache.org/docs/trunk/mod/mod_deflate.html#deflatealteretag
这个博客文章build议完全删除Etags并依赖Cache-Control头。
要在httpd.conf做到这一点:
<IfModule mod_headers.c> Header unset ETag </IfModule> FileETag None
请注意,如果mod_deflate实体gzip:ed仍然携带与简单实体相同的ETag,则这可能会导致ETag感知代理caching不一致。
更多信息:
你能详细说明你如何configurationgzip吗? 例如,你使用mod_deflate? 你能从你的httpd.conf发布片段,特别是AddOutputFilterByType字段吗? 我遵循这些方向为我的特定托pipe服务提供商,这可能是文本/ CSS不在您的托pipe服务提供商列表中:
http://kb.mediatemple.net/questions/1567/Compressing+web+pages+with+mod_deflate