简体   繁体   中英

deflate/gzip compression not working

I have classic shared hosting(apache). In phpinfo() it's both enabled.

gzip compression enabled

I tried to use this:

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

Also this:

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

But it's not working for me. Response headers are:

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

so it's missing Content-Encoding gzip . If I run my script using this it shows me

It's GZIP Enabled.72.9% Was saved by compressing this page with GZIP.

But in my code it's not working(there's no compression). What should I do/try?

I think that compression is working OK. Server does not respond as expected because, according RFC , you need to specify that you want to have compressed response by adding Accept-Encoding header with one of supported content-codings to your request.

Accept-Encoding: gzip, deflate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM