views:

1769

answers:

6

I serve pre-compressed CSS and JS files on my site, and IE6-8 and FF is working perfectly with my .htaccess file.

# Compressed files
RewriteCond %{HTTP:Accept-Encoding} .*gzip.*
AddEncoding x-gzip .gz
AddType application/x-javascript .gz
AddType text/css .gz

I call the files with the .gz extension already [example]:

<link rel="stylesheet" type="text/css" media="all" href="css/layout.css.gz" />

So why is this breaks in google Chrome?

Thanks.

+3  A: 

Download Fiddler and look at the raw response headers to see what the server is sending back for that particular request.

FYI, Fiddler is a client side proxy that filters your browser requests through. Super informative when dealing with these kind of issues.

-- Update

Upon further investigation, it doesn't appear that your RewriteCond is actually doing what you think it is doing. According to the Documentation, the RewriteCond directive is only used in conjunction with a RewriteRule.

Jordan S. Jones
A: 

Google Chrome (and Apple Safari) do not support gzip compressed CSS and JavaScript. Certain IE6 versions also have problems. They do support gzip compressed HTML documents, but not CSS and JavaScript.

elmuerte
how can I filter those who not support in my htaccess file ?
vsync
You shouldn't link to the .gz files directly from your HTML. You could use mod_rewrite or (even better) mod_negotiation so send the gzip compressed file instead.
elmuerte
or just yui compress them, which will give you valid JS and comparable compression savings
annakata
YUI compression is no where close to gzip compression. Usually you would also gzip the result of YUI.See: http://www.julienlecomte.net/blog/2007/08/13/
elmuerte
yes, they are already compressed with Dean's PACKER, but GZIPis by far the best solution. my server doesn't support GZIP on the fly..so I must pre-compressed them. mod_rewrite doesn't work.even if it did, would it help in Chrome case?
vsync
I'm not sure if the Chrome/Safari comment is all that accurate as I am currently using GZip compressed CSS and Javascript successfully.
Jordan S. Jones
Untrue. Current versions of Safari and all versions of Chrome support GZIP just fine.
EricLaw -MSFT-
Not for JavaScript and CSS. GZIPed HTML documents work just fine, but when the browser requests the linked javascript and css files it will drop the support for gzip (just check the request headers and you'll see).
elmuerte
This is simply not true. All JS/CSS requests in these browsers are sent with "Accept-Encoding: gzip,deflate". It's possible you have a proxy/antivirus that's munging this request header in order to more easily scan your JS/CSS files. Go to a site that lists your request headers and you'll probably see a header like "Accept-Enc!ding".
mrclay
-1. Simply False. As an example yahoo.com serves gzipped stylesheets and javascript files and works fine in Google Chrome. I'll reconsider my vote if you prove you're right (for example referencing a reliable source)
Andrea Zilio
@Andrea Zilio: that's probably because it has been fixed in recent Chrome versions. Up to and including Chrome 2.x did not like gzip compressed css/javascript files.You should never rely on the user agent to serve gzip compressed files, always rely on the presence of "Accept-Encoding" containing either gzip or deflate.
elmuerte
A: 

You would just need to set the Content-Encoding header field to tell the client, that the response data is encoded with gzip:

<FilesMatch "\.gz$">
    Header set Content-Encoding gzip
</FilesMatch>

But unfortunatly Apache doesn’t allow to set that header field. Instead Content-Encoding will become X-Content-Encoding.

Gumbo
so what does that mean if it will become with X prefix?
vsync
It means that it will not be recognized.
Gumbo
A: 

1> You must use the "Content-Encoding: gzip" response header. 2> You must only return GZIP compressed content when the client's "Accept-Encoding" header allows GZIP.

EricLaw -MSFT-
+2  A: 

Our .htaccess file (we have .jsz files with compressed javascript, and Chrome handles them fine):

AddEncoding gzip .jsz
AddType text/javascript .jsz
David
A: 

Hi vsync,

I answered a similar question with a much more conservative matching rule for when to Gzip:

Safari, Chrome, and IE6 all have problems with Gzipped downloads. Also, Apache will do the gzip compression for you, there is no need to manually gzip files. Try this snippet:

# This uses mod_deflate, which is pretty standard on Apache 2.  Loading
# mod_deflate looks like this:
#
#   LoadModule deflate_module modules/mod_deflate.so
#
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html

See the original post: http://stackoverflow.com/questions/1245889/htaccss-file-to-allow-safari-other-browsers-to-open-gzip/1245948#1245948

mixonic
i fail to see where your configuration will prevent gzip taking place for chrome browser...
HorusKol