Html 什么是 gZip 压缩?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16691506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is gZip compression?
提问by Ric
I have heard a lot that one should use gZipfor their webpages for faster access and downloads, and that it also saves the bandwidth.
我听说过很多人应该将gZip用于他们的网页,以便更快地访问和下载,并且它还可以节省带宽。
So what is this gZip compression and how does it make the downloads faster ? Does it compress the HTML and images or just the HTML.
那么这个 gZip 压缩是什么以及它如何使下载速度更快?它是压缩 HTML 和图像还是仅压缩 HTML。
If I am to start using gZip in my webapps what considerationsdo I need to make ? Are there any server or browser restrictionsfor it, or does it support a particular encoding only.
如果我要开始在我的 web 应用程序中使用 gZip,我需要考虑什么?是否有任何服务器或浏览器限制,或者它是否仅支持特定编码。
回答by Spudley
GZip is a form of data compression -- ie it takes a chunk of data and makes it smaller. The original data can be restored by un-zipping the compressed file.
GZip 是一种数据压缩形式——即它需要一大块数据并使其更小。可以通过解压缩压缩文件来恢复原始数据。
It is relevant to web apps and web sites because the HTTP protocol includes the ability to gzip data that is being sent.
它与网络应用程序和网站相关,因为 HTTP 协议包括对正在发送的数据进行 gzip 压缩的能力。
This means that when it is in use, your bandwidth costs for serving the site will be lower because people visiting the site will be downloading file that has been made smaller files.
这意味着在使用它时,您为该站点提供服务的带宽成本将降低,因为访问该站点的人将下载已制作为较小文件的文件。
There are a few caveats to using GZip, but overall it's usually better to use gzip than not to -- for example, it does take time and processor power to zip and unzip the files, but typically this is not a problem because the time it takes to do that is often less than the time that is saved by downloading a larger file. Therefore the overall effect is a time saving, despite the browser having to unzip the file.
使用 GZip 有一些注意事项,但总的来说,使用 gzip 通常比不使用要好——例如,压缩和解压缩文件确实需要时间和处理器能力,但通常这不是问题,因为它的时间这样做所需的时间通常少于下载更大文件所节省的时间。因此,尽管浏览器必须解压缩文件,但总体效果是节省时间。
GZip can compress all files; it doesn't make any difference what the file type is or the encoding. Obviously some files can be compressed more effectively than others, so the bandwidth saving will vary - text files like HTML give the best results; images are not compressed so much by gzip because they already have some compression built-in. Some files (eg those that are already heavily compressed like .zip
files) may actually get slightly bigger when gzipped, because they can't be compressed any futher but gzip still needs to add it's meta data to the file. But these are edge cases, and don't make much difference.
GZip 可以压缩所有文件;文件类型或编码没有任何区别。显然,有些文件比其他文件压缩得更有效,因此节省的带宽会有所不同——HTML 等文本文件的效果最好;图像没有被 gzip 压缩太多,因为它们已经内置了一些压缩。一些文件(例如那些已经像.zip
文件一样被大量压缩的文件)在 gzip 时实际上可能会稍微变大,因为它们不能被进一步压缩,但 gzip 仍然需要将它的元数据添加到文件中。但这些都是边缘情况,没有太大区别。
GZip across HTTP normally happens completely transparently. The end user should be completely unaware that it is happening; the browser would do it behind the scenes for them. And from the web server end it is simply a matter of turning on a config setting in your web server software. From your perspective, that's really all you need to know; just set the gzip setting on your server (or ask your ISP to do it). It's quite possible it may already be active on your site without you even knowing.
HTTP 上的 GZip 通常完全透明地发生。最终用户应该完全不知道它正在发生;浏览器会在幕后为他们做这件事。从 Web 服务器端,只需打开 Web 服务器软件中的配置设置即可。从你的角度来看,这就是你真正需要知道的;只需在您的服务器上设置 gzip 设置(或要求您的 ISP 进行设置)。它很有可能在您不知情的情况下已经在您的网站上处于活动状态。
回答by Devesh
GZip Compress the files like html , js and css files while serving the request to the browser. As size of the file is reduced it is served to the user in faster manner. Not all the browser support compression but now all the modern browser support. It is highly recommended , but only one part is that it increases the CPU usages of the server which may be concern sometime. Using Gzip with client side caching will help in increasing the performance.
GZip 在向浏览器提供请求的同时压缩 html 、 js 和 css 文件等文件。随着文件大小的减小,它以更快的方式提供给用户。并非所有浏览器都支持压缩,但现在所有现代浏览器都支持。强烈推荐,但只有一个部分是它会增加服务器的 CPU 使用率,这有时可能会引起关注。将 Gzip 与客户端缓存一起使用将有助于提高性能。
回答by GoCityAd App
Gzip is a method to compress javascript and css so increase web page speed ultimatly our website load time decrising than overall speed incresed
Gzip 是一种压缩 javascript 和 css 的方法,因此最终提高了网页速度,我们的网站加载时间比整体速度增加了