gzip working but YSlow indicates it's not

做~自己de王妃 提交于 2019-12-21 17:34:55

问题


I'm getting used to Firebug and YSlow in particular. One of the things I'm looking at is the gzip compression. YSlow still gives my site an "F" and indicates that my CSS and JavaScript files are not being compressed.

However, if I run an external gzip test against my site (such as http://www.gidnetwork.com/tools/gzip-test.php) it tells me that gzip is working and gives me my savings, although I think this may just be the HTML.

This is the relevant section of my .htaccess file:

<IfModule mod_gzip.c>
    mod_gzip_on       Yes
    mod_gzip_dechunk  Yes
    mod_gzip_item_include file      \.css$
    mod_gzip_item_include file      \.(html?|txt|js|php|pl|jpg|png|gif)$
    mod_gzip_item_include handler   ^cgi-script$
    mod_gzip_item_include mime      ^text/.*
    mod_gzip_item_include mime      ^application/x-javascript.*
    mod_gzip_item_exclude mime      ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

Why does YSlow not agree with the external gzip test?


回答1:


mod_gzip is an obsolete part of Apache 1.x, having been replaced by mod_deflate in Apache 2.

This mod_deflate configuration makes YSlow happy here:

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

The only reason there are two AddOutputFilterByType lines is to avoid horizontal scrolling.




回答2:


Not measuring behind a proxy? My work proxy screws with my yslow results...!




回答3:


Just add the next code to your .htaccess

# BEGIN GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
# END GZIP

Seems it makes both GTmetrix & Yslow happy

Don't forget to add

ob_start("ob_gzhandler");

at the beginning of your header file if your are using PHP



来源:https://stackoverflow.com/questions/5603739/gzip-working-but-yslow-indicates-its-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!