我在用着mod_deflate on 阿帕奇2.2压缩级别设置为 9。我根据以下建议对网站的每个可能的方面进行了微调Y慢 (v2)并在所有类别上均取得了总体 A 级(总分:91),除了:
- 减少 HTTP 请求(Grade C-
我还在进一步努力
图像统一)
- 使用 gzip 压缩组件(Grade
F)
YSlow still reports back with a F and tells me to use gzip on my CSS and JS files. Here's a screenshot of the YSlow report (the domain has been blurred out for the sake of privacy):
然而,像这样的网站GIDNetwork GZIP 测试 http://www.gidnetwork.com/tools/gzip-test.php报告完美压缩!
我的 .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>
谁能指出我哪里出错了?
谢谢,
米^e
mod_deflate 可能配置不正确。
典型的 mod_deflate 配置可能会根据用户代理字符串排除某些浏览器,并且可能仅配置为压缩某些文件类型 - 由在服务器上注册的 MIME 类型标识。
您应该压缩所有 HTML、CSS 和 Javascript 文件,但不压缩 PNG、GIF 或 JPEG 文件,而且 Netscape 4 存在一些您可能不想考虑的错误。尝试使用文档中的示例代码 http://httpd.apache.org/docs/2.2/mod/mod_deflate.html#recommended:
<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>
还要注意,您发布的 GIDZipTest GZIP 测试不会测试关联的 Javascript 和 CSS 文件,而 YSlow 会测试 - 在 GIDZipTest GZIP 测试中,您需要单独测试这些文件。
我猜你的 ISP 也可能正在使用缓存代理(透明或不透明),这会破坏或删除你的 Accept-Encoding: 标头。要排除这个原因,您可以请某人从 ISP 外部对其进行测试。
另一件需要注意的事情是,当使用 gzip 压缩文件时,您是以带宽换取 CPU 时间。高于较低的压缩强度,您会发现带宽节省的回报递减,但所需的 CPU 时间却大幅增加。不幸的是,当压缩强度高达 9 时,您几乎肯定会浪费太多 CPU 时间而几乎没有改进压缩 - 我始终建议使用强度 1。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)