【发布时间】:2014-03-14 00:14:31
【问题描述】:
我正在尝试压缩我的网站。但我不确定它是否真的有效..
当我在 checkgzipcompression.com、WhatsMyIP.org 和 YSlow 上查看时,它们都告诉我该站点没有被压缩。 Yslow 还告诉我,我有几个未压缩的文件,当然建议我这样做。
这是我的htaccess-文件中应该压缩站点的部分:
<IfModule mod_deflate.c>
# Force compression for mangled headers.
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
# Compress all output labeled with one of the following MIME-types
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/atom+xml \
application/javascript \
application/json \
application/rss+xml \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/x-web-app-manifest+json \
application/x-httpd-php \
application/x-httpd-fastphp \
application/xhtml+xml \
application/xml \
font/opentype \
image/svg+xml \
image/x-icon \
text/css \
text/html \
text/plain \
text/x-component \
text/xml
</IfModule>
</IfModule>
此代码基于 h5bp (https://github.com/h5bp/html5-boilerplate/blob/v4.3.0/doc/TOC.md)。
如果我将ini_set("zlib.output_compression", 4096); 添加到 PHP 启动脚本 - checkgzipcompression.com 和 WhatsMyIP.org 都告诉我我的网站已压缩。连同以 kb 为单位的页面重量。
但是 YSlow 仍然告诉我我有多个未压缩的文件。
在 chrome 和 firefox 的开发人员工具中,显示每个请求/文件的未压缩文件大小(我不确定它是否应该是这样的(?))。
它确实说 Accept-Encoding: gzip,deflate 和 Vary: Accept-Encoding,但没有像 Content-Encoding: gzip 那样。
我刚刚和我的服务器提供商——BlueHost——聊天,他们说mod_deflate 在他们所有的服务器上自动运行。但由于它是动态的,大多数网站扫描仪都看不到它。
结论是,我无法确定我的网站实际上是压缩的。
.htaccess-文件如上所示,zlib.output_compression() 已关闭 - 以防您有能力查看它..
域名是:http://barkeeper.thomaskile.me
以下是 Firefox 对该页面的评价:
【问题讨论】:
标签: .htaccess gzip mod-deflate