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.
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.
Our .htaccess file (we have .jsz files with compressed javascript, and Chrome handles them fine):
AddEncoding gzip .jsz
AddType text/javascript .jsz
Safari (and Google Chrome) don`t works with compressed file if they extension is .gz
To support gzip archives on Safari and Chrome, copy and compress .css and .js files into gzip and rename they extension a .gz on the .jgz (for example: before - one file style.css into directory after - two files, style.css and style.css.jgz into directory )
And added this code into your .htaccess file:
AddEncoding gzip .jgz
RewriteCond %{HTTP:Accept-encoding} gzip
# RewriteCond %{HTTP_USER_AGENT} !Safari
RewriteCond %{HTTP_USER_AGENT} !Konqueror
RewriteCond %{REQUEST_FILENAME}.jgz -f
RewriteRule ^(.*)$ $1.jgz [QSA,L]
<IfModule mod_headers.c>
Header append Vary User-Agent
<FilesMatch .*\.js.jgz$>
ForceType text/javascript
Header append Vary Accept-Encoding
Header set Content-Encoding: gzip
Header set Cache-control: private
</FilesMatch>
<FilesMatch .*\.css.jgz$>
ForceType text/css
Header append Vary Accept-Encoding
Header set Content-Encoding: gzip
Header set Cache-control: private
</FilesMatch>
</IfModule>
For example megaburg.ru Tested - is working with Safari, Chrome, Opera and Firefox 8)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With