gzip working but YSlow indicates it's not
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 th开发者_如何学Gois 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?
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.
Not measuring behind a proxy? My work proxy screws with my yslow results...!
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
精彩评论