Precompressed gzip break on chrome, why?

I serve pre-compressed CSS and JS files on my site, and IE6-8 and FF work fine 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 extension .gz already [example]:

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

So why are these breaks in Google Chrome?

Thanks.

+4
source share
7 answers

Download Fiddler and look at the original response headers to see what the server sends back for this particular request.

FYI, Fiddler is a client-side proxy that filters your browser requests. Super informative in solving such problems.

- Update

With further research, it looks like your RewriteCond is actually doing what you think it is doing. According to the documentation, the RewriteCond directive is used only in conjunction with a RewriteRule.

+3
source

Safari (and Google Chrome) does not work with a compressed file if the extension is .gz

To support gzip archives in Safari and Chrome, copy and compress .css and .js files to gzip and rename their extension .gz to .jgz (for example: before - one style.css file in the directory after - two files, style.css and style.css.jgz to the directory)

And added this code to 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 - works with Safari, Chrome, Opera and Firefox 8)

+3
source

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

 AddEncoding gzip .jsz AddType text/javascript .jsz 
+2
source
  • You should use the Content-Encoding: gzip response header.
  • You should return only compressed GZIP content if the Accept-Encoding header of the GZIP client.
+1
source

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

Safari, Chrome, and IE6 all have problems loading Gzipped. Also, Apache will perform 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: How can I make my .htaccess file so that Safari and other browsers open gzip?

+1
source

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

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

But, unfortunately, Apache does not allow setting this header field. Instead, Content-Encoding will become X-Content-Encoding .

0
source

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

-2
source

Source: https://habr.com/ru/post/1285873/


All Articles