我正在尝试压缩我的网站。但我不确定它是否真的有效。
当我在 checkgzipcompression.com、WhatsMyIP.org 和 YSlow 上查看时,他们都告诉我该网站没有被压缩。Yslow 还告诉我,我有几个未压缩的文件,当然建议我这样做。
这是我的htaccess
-file 中应该压缩站点的部分:
<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
-file 如上所示,并且zlib.output_compression()
已关闭 - 以防您有能力将其签出..
域名是:http ://barkeeper.thomaskile.me
这是 Firefox 对该页面的评价: