pre-compressed gzip break on chrome, why?

2019-04-10 01:13发布

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.

7条回答
男人必须洒脱
2楼-- · 2019-04-10 01:45

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

AddEncoding gzip .jsz
AddType text/javascript .jsz
查看更多
男人必须洒脱
3楼-- · 2019-04-10 01:46

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: How can I make my .htaccess file allow Safari & other browsers to open GZIP?

查看更多
Deceive 欺骗
4楼-- · 2019-04-10 01:50

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.

查看更多
祖国的老花朵
5楼-- · 2019-04-10 01:54
  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.
查看更多
相关推荐>>
6楼-- · 2019-04-10 01:55

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.

查看更多
Juvenile、少年°
7楼-- · 2019-04-10 01:58

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.

查看更多
登录 后发表回答