YSlow为使用mod_deflate压缩的文件提供F等级

miC*_*inG 6 compression gzip mod-deflate yslow

我在Apache 2.2上使用mod_deflate,压缩级别设置为9.我根据YSlow(v2)的建议调整了网站的每个可能方面,并设法获得整体A级(总分: 91)以及所有类别除外:

  • 减少HTTP请求(C级 - 我仍在努力进一步统一图像)
  • 使用gzip压缩组件(F级)

YSlow仍然用F报告,并告诉我在我的CSS和JS文件上使用gzip.以下是YSlow报告的截图(该域名因隐私而模糊不清):YSlow报告的屏幕截图:http: //img29.imageshack.us/img29/9160/yslowreportdomainblurre.jpg

但是,像GIDNetwork GZIP Test这样的网站报告完美的压缩!

我的.htaccess的mod_deflate部分

# Below uses mod_deflate to compress text files. Never compress binary files.
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE

# compress content with type html, text, js, and css
AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript text/xml image/svg+xml application/javascript application/x-javascript application/atom_xml application/rss+xml application/xml application/xhtml+xml application/x-httpd-php application/x-httpd-fastphp

# Properly handle old browsers that do not support compression  
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# Explicitly exclude binary files from compression just in case
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-vary

# properly handle requests coming from behind proxies
Header append Vary User-Agent env=!dont-vary
</IfModule>
Run Code Online (Sandbox Code Playgroud)

任何人都可以指出我哪里出错了?

谢谢,m ^ e

tho*_*ter 4

mod_deflate 可能配置不正确。

典型的 mod_deflate 配置可能会根据用户代理字符串排除某些浏览器,并且可能仅配置为压缩某些文件类型 - 由在服务器上注册的 MIME 类型标识。

您应该压缩所有 HTML、CSS 和 Javascript 文件,但不压缩 PNG、GIF 或 JPEG 文件,而且 Netscape 4 存在一些您可能不想考虑的错误。尝试使用文档中的示例代码

<Location />
    # 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
    # Don't compress images
    SetEnvIfNoCase Request_URI \
    \.(?:gif|jpe?g|png)$ no-gzip dont-vary

    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary
</Location> 
Run Code Online (Sandbox Code Playgroud)

还要注意,您发布的 GIDZipTest GZIP 测试不会测试关联的 Javascript 和 CSS 文件,而 YSlow 会测试 - 在 GIDZipTest GZIP 测试中,您需要单独测试这些文件。

我猜你的 ISP 也可能正在使用缓存代理(透明或不透明),这会破坏或删除你的 Accept-Encoding: 标头。要排除这个原因,您可以请某人从 ISP 外部对其进行测试。

另一件需要注意的事情是,当使用 gzip 压缩文件时,您是以带宽换取 CPU 时间。高于较低的压缩强度,您会发现带宽节省的回报递减,但所需的 CPU 时间却大幅增加。不幸的是,当压缩强度高达 9 时,您几乎肯定会浪费太多 CPU 时间而几乎没有改进压缩 - 我始终建议使用强度 1。

  • 您是否有可能在 Firefox 上通过代理访问该网站?代理可能会删除浏览器发送的 Accept-Encoding: 标头,以便缓存它(代理也可以是透明的)。让 ISP 之外的人用他们自己的 Firefox 进行检查可以确认或排除这个原因。 (2认同)