deflate / gzip压缩无法正常工作

时间:2015-08-03 15:35:05

标签: php .htaccess compression gzip

我有经典的共享主机(apache)。在phpinfo()中,它都启用了。

  

启用gzip压缩

我试着用这个:

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

还有:

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE application/x-javascript application/javascript text/javascript text/css text/html text/xml
</IfModule>

但它不适合我。响应标头是:

HTTP/1.1 200 OK
Date: Mon, 03 Aug 2015 15:29:08 GMT
Server: Apache
Last-Modified: Mon, 03 Aug 2015 14:28:34 GMT
ETag: "64325f33-1ebd5-51c68fc093cbc"
Accept-Ranges: bytes
Cache-Control: max-age=604800
Expires: Mon, 10 Aug 2015 15:29:08 GMT
Vary: Accept-Encoding
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: application/javascript
Transfer-Encoding: chunked

所以它缺少Content-Encoding gzip。如果我使用this运行我的脚本,它会显示我

  

启用了GZIP.72.9%   通过使用GZIP压缩此页面来保存。

但在我的代码中,它不起作用(没有压缩)。我该怎么做/尝试?

1 个答案:

答案 0 :(得分:1)

我认为压缩工作正常。服务器没有按预期响应,因为according RFC,您需要通过向您的请求添加支持content-codings的Accept-Encoding标头来指定您希望获得压缩响应。

Accept-Encoding: gzip, deflate