如何判断我的服务器是否正在提供 GZipped 内容?
我在 NGinx 服务器上有一个 Web 应用程序。我在conf文件中设置了gzip on
,现在我试图看看它是否有效。 YSlow 说不是,但进行测试的 6 个网站中有 5 个表示是。我怎样才能得到明确的答案以及为什么结果会有所不同?
I have a webapp on a NGinx server. I set gzip on
in the conf file and now I'm trying to see if it works. YSlow says it's not, but 5 out of 6 websites that do the test say it is. How can I get a definite answer on this and why is there a difference in the results?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
不出所料,看起来一个可能的答案是
curl
:在第二种情况下,客户端告诉服务器它支持内容编码,您可以看到响应确实更短,经过压缩。
It looks like one possible answer is, unsurprisingly,
curl
:In the second case the client tells the server that it supports content encoding and you can see that the response was indeed shorter, compressed.
更新
Chrome 更改了报告方式(如果感兴趣,请参阅原始答案)。您可以使用开发人员工具 (F12) 来判断。转到“网络”选项卡,选择要检查的文件,然后查看右侧的“标头”选项卡。如果您经过 gzip 压缩,那么您将在内容编码中看到它。
在此示例中,slider.jpg 确实被 gzip 压缩。
将其与您所在的页面进行比较并查看 png 文件,您将看不到这样的指定。
需要明确的是,这并不是因为一个是 jpg,一个是 png。这是因为一个是 gzip 压缩的,而另一个则没有。
上一个答案
在 Chrome 中,如果您打开开发者工具并转到“网络”选项卡,那么如果没有压缩,它将显示以下内容:
如果存在压缩,则以下内容:
也就是说,同一个数字,顶和底部,意味着没有压缩。
Update
Chrome changed the way it reports (see original answer if interested). You can tell using Developer Tools (F12). Go to the Network tab, select the file you want to examine and then look at the Headers tab on the right. If you are gzipped, then you will see that in the Content-Encoding.
In this example, slider.jpg is indeed being gzipped.
Compare that to this very page that you are on and look at a png file, you will see no such designation.
Just to be clear, it isn't because one is a jpg and one is a png. It is because one is gzipped and the other one isn't.
Previous Answer
In Chrome, if you pull up the Developer Tools and go to the Network tab, then it will show the following if there is no compression:
And the following if there IS compression:
In other words, the same number, top and bottom, means no compression.
请参阅响应标头。在 FireFox 中,您可以使用 Firebug 检查。
如果服务器支持 gzip 内容,则应显示此内容。
See in the response headers. In FireFox you may check with Firebug.
If server supports gzip content then this should be displayed.
在新版chrome中,开发者工具>网络,您可以右键单击列名称,然后选择内容编码选项并添加该列(图像中的黑框)。
如果您想查看 gzip 内容的大小(如 @Outfast Source),您可以单击“查看”旁边的图标(在图像中显示为绿色框)。
这样您就可以看到哪些内容启用了 gzip。
In new version of chrome, Developer tools > network, you can right click on Column name, and select content-encoding option and add that column (black box in image).
and if you want to see the size of that gzip content, as @Outfast Source - than you can click on icon which is next to View (displayed as Green box in image).
so you can see which content is gzip enabled.
您可以快速使用 Web 服务,例如: http://www.whatsmyip.org/http-compression -test/
Google Chrome 开发者工具中的“审核”工具也派上用场。
You could quickly use a web service like: http://www.whatsmyip.org/http-compression-test/
Google Chrome's "Audits" tool in the developer tools comes in handy as well.
我根据zoul的回答编写了这个脚本:
示例:
I wrote this script based on the zoul's answer:
example:
由于这是 google 中的第一个搜索结果,我将编辑其中一个答案以包含 Brotli 压缩,它的短名称是
br
,您可以将它与curl
一起使用或者在浏览器中通过F12
观看。对于 @zoul 编辑的
curl
答案:since it's first search result in google, I'm going to edit one of the answers to include Brotli compression too, its short name is
br
and you can use it withcurl
or watch for it viaF12
in browser.for
curl
edited from @zoul answer:这是我的一句台词:
file
命令行工具告诉您它是什么类型的文件。你应该看到这个:Here's my one-liner:
The
file
command line tool tells you what type of file it is. You should see this: