1

我正在尝试压缩我的网站。但我不确定它是否真的有效。
当我在 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 对该页面的评价: 火狐开发工具

4

1 回答 1

-1

Bluehost 也有同样的问题。我检查了实际的文件大小,它们没有被压缩。得到了与它自动相同的BS。首先,他们试图告诉我它仅在服务器负载过重时才有效……显然那个人一无所知。然后我被告知服务器负载阈值很低,并且在超过该阈值时禁用了压缩。我对到处都是这些答案感到非常沮丧。

于 2014-02-15T21:22:33.320 回答