Chrome Devtool不会在响应标头中显示Content-Encoding

时间:2015-02-13 11:30:51

标签: .htaccess google-chrome pagespeed mod-deflate

我启用gzip压缩以提高Google PageSpeed Insights的速度:

如果压缩mantaspersonalizadas.com/fonts/Cocktail-Shaker.svg,将节省144.1 KB(减少65%)。 如果压缩mantaspersonalizadas.com/fonts/Cocktail-Shaker.ttf,将节省62.6 KB(减少49%)。 如果压缩mantaspersonalizadas.com/fonts/Cocktail-Shaker.woff,将节省2.6 KB(减少5%)。

我使用Apache服务器,我将此代码添加到.htacess:

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/opentype

# For Olders Browsers Which Can't Handle Compression
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

如何检查我的本地服务器是否启用了deflate?

Chrome DevTools不显示Content-Enconding: enter image description here

3 个答案:

答案 0 :(得分:3)

让我们进行测试。

对example.com的Chrome请求(包含gzip):

GET / HTTP/1.1
Host: www.example.com
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
If-None-Match: "359670651"
If-Modified-Since: Fri, 09 Aug 2013 23:54:35 GMT

来自example.com的Chrome响应(不包含gzip):

HTTP/1.1 304 Not Modified
Accept-Ranges: bytes
Cache-Control: max-age=604800
Date: Thu, 08 Dec 2016 14:06:04 GMT
Etag: "359670651"
Expires: Thu, 15 Dec 2016 14:06:04 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (iad/182A)
Vary: Accept-Encoding
X-Cache: HIT

卷曲请求(Chrome请求的克隆,包含gzip):

curl -I
    -H "GET / HTTP/1.1"
    -H "Host: www.example.com"
    -H "Connection: keep-alive"
    -H "Cache-Control: max-age=0"
    -H "Upgrade-Insecure-Requests: 1"
    -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36"
    -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
    -H "Accept-Encoding: gzip, deflate, sdch"
    -H "Accept-Language: en-US,en;q=0.8"
    -H "If-None-Match: "359670651""
    -H "If-Modified-Since: Fri, 09 Aug 2013 23:54:35 GMT"
    example.com

卷曲响应(包含gzip):

HTTP/1.1 200 OK
Content-Encoding: gzip
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Thu, 08 Dec 2016 14:18:34 GMT
Etag: "359670651"
Expires: Thu, 15 Dec 2016 14:18:34 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (iad/182A)
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 606

<强>结论

Chrome当前未显示内容编码。 Firefox也没有。我不知道为什么。

既然我知道他们并没有向我展示一切,我再也不会相信回复标题信息了。

一路卷曲。

答案 1 :(得分:2)

这似乎是一个问题Chrome浏览器,我有同样的问题我虽然deflate在服务器上没有工作,但后来我尝试了Firefox并使用了firebug,它在标题中正确显示了Content-Encoding。

Chrome中下载的文件大小也没有显示未压缩的文件大小,而Firefox则显示正确的压缩文件大小。

答案 2 :(得分:0)

如@Jay stated

  

Chrome当前不显示内容编码。 Firefox也没有。我不知道为什么。

截至2018年12月,Chrome和Firefox中的相同行为以及Firebug均已消失。

Firefox Developer Edition帮了我大忙,在响应标头部分显示了正确的内容编码([F12]->网络选项卡->选择资源->标头选项卡)。

Screenshot: content encoding shows up in Firefox Developer Tools