我使用 Google Chrome,并尝试使用内置的开发人员工具网络监视器 (F12) 检查我的网站是否启用了 gzip 压缩。在线工具显示我的网站已压缩,但我的浏览器显示的大小不同,我使用以下方法进行了测试https://superuser.com,现在来看看结果:
测试A
W10 64 位、Google Chrome 64 位、仅限 IPv4
accept-ranges:bytes
cache-control:private
content-encoding:gzip
content-length:27980
content-security-policy-report-only:default-src https: wss: data: blob: 'unsafe-eval' 'unsafe-inline'; report-uri https://stackoverflow.report-uri.io/r/default/csp/reportOnly
content-type:text/html; charset=utf-8
date:Sat, 18 Nov 2017 12:32:50 GMT
status:200
strict-transport-security:max-age=15552000
vary:Accept-Encoding,Fastly-SSL
via:1.1 varnish
x-cache:MISS
x-cache-hits:0
x-dns-prefetch-control:off
x-frame-options:SAMEORIGIN
x-request-guid:e8e35c63-8ada-4304-9775-518e2c94493a
x-served-by:cache-hhn1546-HHN
x-timer:S1511008370.083090,VS0,VE93
网络监视器:
168 KB
162 KB
第一个值是压缩后的大小,它比未压缩后的大小大?!为什么它不同于content-length
?
https://cdn.sstatic.net/Js/stub.en.js?v=50f40f106ebf响应头:
accept-ranges:bytes
age:155455
cache-control:max-age=604800
content-encoding:gzip
content-length:13501
content-type:application/javascript
date:Sat, 18 Nov 2017 12:32:50 GMT
etag:"06eea28ff5ed31:0"
last-modified:Thu, 16 Nov 2017 17:20:12 GMT
status:200
vary:Accept-Encoding,Accept-Encoding
via:1.1 varnish
x-cache:HIT
x-cache-hits:51733
x-served-by:cache-hhn1543-HHN
x-timer:S1511008370.272246,VS0,VE0
网络监视器:
13.3 KB
38.2 KB
这看起来正确。
测试 B
W10 64 位、Google Chrome 62 位、仅 IPv6(朋友的另一个位置)
Accept-Ranges:bytes
Cache-Control:private
Connection:keep-alive
Content-Length:101440
Content-Security-Policy-Report-Only:default-src https: wss: data: blob: 'unsafe-eval' 'unsafe-inline'; report-uri https://stackoverflow.report-uri.io/r/default/csp/reportOnly
Content-Type:text/html; charset=utf-8
Date:Sat, 18 Nov 2017 12:34:04 GMT
Set-Cookie:prov=48760143-4086-135d-440f-590d1ece722d; domain=.superuser.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
Strict-Transport-Security:max-age=15552000
Vary:Accept-Encoding,Fastly-SSL
Via:1.1 varnish
X-Cache:MISS
X-Cache-Hits:0
X-DNS-Prefetch-Control:off
X-Frame-Options:SAMEORIGIN
X-Request-Guid:acf51572-2f08-4ef0-9695-d7217182eb1c
X-Served-By:cache-hhn1533-HHN
X-Timer:S1511008444.161788,VS0,VE102
网络监视器:
99.9 KB
99.1 KB
https://cdn.sstatic.net/Js/stub.en.js?v=50f40f106ebf响应头:
Accept-Ranges:bytes
Age:155530
Cache-Control:max-age=604800
Connection:keep-alive
Content-Length:39076
Content-Type:application/javascript
Date:Sat, 18 Nov 2017 12:34:05 GMT
ETag:"06eea28ff5ed31:0"
Last-Modified:Thu, 16 Nov 2017 17:20:12 GMT
Vary:Accept-Encoding,Accept-Encoding
Via:1.1 varnish
X-Cache:HIT
X-Cache-Hits:52224
X-Served-By:cache-hhn1529-HHN
X-Timer:S1511008445.494412,VS0,VE0
网络监视器:
38.6 KB
38.2 KB
现在,虽然浏览器要求压缩网站,但 gzip 内容却完全丢失:
GET / HTTP/1.1
Host: superuser.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
Upgrade-Insecure-Requests: 1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
Google Chrome 中的网络监视器有问题吗?原因可能是什么测试 B没有收到 superuser.com 的 gzip 版本?
答案1
这看起来像是一个错误:
参考
为什么 Gzip 无法在 Chrome 上运行? - 堆栈内存溢出
763700 - DevTools:HTML 文档压缩大小不正确 - chromium - Monorail
在某些情况下,防病毒软件可能是罪魁祸首。Nginx gzip 在 Chrome 中不起作用 - 代码日志