5
votes

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?

3
Apologies, the line breaks in my code sample seem to have been lost. Any help greatly appreciated. - scm8jet
It appears you're asking for gzip on jpg png and gif, there's no point, zlib can't improve upon these. (No idea on the actual point of your question. Sorry. :) - sarnold
Hi sarnold, Any ideas on if gzip is not working for css/javascript on my site, or if YSlow is not recognizing the compression. Basically I'm trying to gzip the files on my website using the code above, however YSlow is saying that my css and javascript files are not being compressed when I believe they should. I believe css, html, txt, js, php, pl, jpg, png and gif files should be compressed but I dont think this is happening. Any ideas - scm8jet
@scm8jet, what do the headers look like when you use a tool like HEAD to retrieve the headers, or look at the headers with Wireshark when using a browser? - sarnold
@sarnold, thanks for coming back to me. I'm not familiar with HEAD, do you have a URL to point me in the right direction? Thanks - scm8jet

3 Answers

2
votes

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.

0
votes

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

0
votes

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