I am trying to find out if there are any principles in defining which pages should be gzip-compressed and to draw a line when to send plain html content.
我试图找出是否有任何原则来定义哪些页面应该是gzip压缩的,并在发送简单的html内容时画一条线。
It would be helpful if you guys can share the decisions you took in gzip-compressing a part of your project.
如果你们可以分享你在gzip压缩项目的一部分时所做的决定,那将会很有帮助。
6 个解决方案
#1
7
A good idea is to benchmark, how fast is the data coming down v.s. how well compressed is it. If it takes 5 seconds to send something that went from 200K to 160K it's probably not worth it. There is a cost of compression on the server side and if the server gets busy it might not be worth it.
一个好主意是基准测试,数据下降速度有多快。压缩程度如何?如果需要5秒钟才能发送从200K到160K的东西,那可能不值得。服务器端有压缩成本,如果服务器忙,可能不值得。
For the most part, if your server load is below 0.8 regularly, I'd just gzip anything that isn't binary like jpegs, pngs and zip files.
在大多数情况下,如果你的服务器负载经常低于0.8,我只是gzip任何非二进制的东西,如jpegs,pngs和zip文件。
There's a good write up here:
这里写得很好:
#2
4
Unless your server's CPU is heavily utilized, I would always use compression. It's a trade-off between bandwidth and CPU utilization, and webservers usually have plenty of spare CPU cycles to spare.
除非你的服务器的CPU被大量使用,否则我总是会使用压缩。这是带宽和CPU利用率之间的权衡,Web服务器通常有足够的备用CPU周期。
#3
4
I don't think there's a good reason not to gzip HTML content.
我认为没有理由不gzip HTML内容。
It takes very little CPU power for big gains in loading speed.
它只需很少的CPU功率即可实现加载速度的大幅提升。
#4
4
There's one notable exception: There's a bug in Internet Explorer 6, that makes all compressed content turn up blank.
有一个值得注意的例外:Internet Explorer 6中存在一个错误,它会使所有压缩内容变为空白。
#5
2
Considering there is a huge gain on the size of the HTML data to download when it's gzipped, I don't see why you shouldn't gzip it.
考虑到在压缩时要下载的HTML数据的大小有很大的增长,我不明白为什么你不应该gzip它。
Maybe it uses a little bit of CPU... But not that much ; and it's really interesting for the client, who has less to download. And it's only a couple of lines in the webserver configuration to activate it.
也许它使用了一点CPU ...但不是那么多;这对于下载量较少的客户来说非常有趣。并且在Web服务器配置中只有几行才能激活它。
(But let your webserver do that : there are modules like mod_deflate
for the most used servers)
(但是让你的网络服务器这样做:对于最常用的服务器,有mod_deflate等模块)
As a semi-sidenote : you are talking about compressing HTML content pages... But stop at HTML pages : you can compress JS and CSS too (they are text files, and, so, are generally compressed really well), and it doesn't cost much CPU either.
作为一个半旁注:你在谈论压缩HTML内容页面...但是停在HTML页面:你也可以压缩JS和CSS(它们是文本文件,因此,通常压缩得非常好),并且它不会也要花费很多CPU。
Considering the big JS/CSS Frameworks in use nowadays, the gain is probably even more consequent by compressing those than by compressing HTML pages.
考虑到现在使用的大型JS / CSS框架,通过压缩这些增益可能比压缩HTML页面更有可能。
#6
2
We made the decision to gzip all content since spending time determining what to gzip or what not to gzip did not seem worth the effort. The overhead of gzipping everything is not significantly higher than gzipping nothing.
我们决定对所有内容进行gzip,因为花时间确定gzip是什么或gzip什么不值得努力。 gzipping一切的开销并不比gzipping什么都高。
This webpage suggests:
该网页建议:
"Servers choose what to gzip based on file type, but are typically too limited in what they decide to compress. Most web sites gzip their HTML documents. It's also worthwhile to gzip your scripts and stylesheets, but many web sites miss this opportunity. In fact, it's worthwhile to compress any text response including XML and JSON. Image and PDF files should not be gzipped because they are already compressed. Trying to gzip them not only wastes CPU but can potentially increase file sizes."
“服务器根据文件类型选择gzip的内容,但是他们决定压缩的内容通常太有限了。大多数网站都会对他们的HTML文档进行gzip。也很有必要对你的脚本和样式表进行gzip,但很多网站都错过了这个机会。事实上,压缩包括XML和JSON在内的任何文本响应都是值得的。图像和PDF文件不应该被压缩,因为它们已经被压缩了。尝试gzip它们不仅浪费CPU,而且可能会增加文件大小。“
If you care about cpu time, I would suggest not gzipping already compressed content. Remember when adding complexity to a system that Programmers/sys admins are expensive, servers are cheap.
如果你关心cpu时间,我建议不要压缩已经压缩的内容。请记住,当为程序员/系统管理员付出昂贵代价的系统增加复杂性时,服务器便宜。
#1
7
A good idea is to benchmark, how fast is the data coming down v.s. how well compressed is it. If it takes 5 seconds to send something that went from 200K to 160K it's probably not worth it. There is a cost of compression on the server side and if the server gets busy it might not be worth it.
一个好主意是基准测试,数据下降速度有多快。压缩程度如何?如果需要5秒钟才能发送从200K到160K的东西,那可能不值得。服务器端有压缩成本,如果服务器忙,可能不值得。
For the most part, if your server load is below 0.8 regularly, I'd just gzip anything that isn't binary like jpegs, pngs and zip files.
在大多数情况下,如果你的服务器负载经常低于0.8,我只是gzip任何非二进制的东西,如jpegs,pngs和zip文件。
There's a good write up here:
这里写得很好:
#2
4
Unless your server's CPU is heavily utilized, I would always use compression. It's a trade-off between bandwidth and CPU utilization, and webservers usually have plenty of spare CPU cycles to spare.
除非你的服务器的CPU被大量使用,否则我总是会使用压缩。这是带宽和CPU利用率之间的权衡,Web服务器通常有足够的备用CPU周期。
#3
4
I don't think there's a good reason not to gzip HTML content.
我认为没有理由不gzip HTML内容。
It takes very little CPU power for big gains in loading speed.
它只需很少的CPU功率即可实现加载速度的大幅提升。
#4
4
There's one notable exception: There's a bug in Internet Explorer 6, that makes all compressed content turn up blank.
有一个值得注意的例外:Internet Explorer 6中存在一个错误,它会使所有压缩内容变为空白。
#5
2
Considering there is a huge gain on the size of the HTML data to download when it's gzipped, I don't see why you shouldn't gzip it.
考虑到在压缩时要下载的HTML数据的大小有很大的增长,我不明白为什么你不应该gzip它。
Maybe it uses a little bit of CPU... But not that much ; and it's really interesting for the client, who has less to download. And it's only a couple of lines in the webserver configuration to activate it.
也许它使用了一点CPU ...但不是那么多;这对于下载量较少的客户来说非常有趣。并且在Web服务器配置中只有几行才能激活它。
(But let your webserver do that : there are modules like mod_deflate
for the most used servers)
(但是让你的网络服务器这样做:对于最常用的服务器,有mod_deflate等模块)
As a semi-sidenote : you are talking about compressing HTML content pages... But stop at HTML pages : you can compress JS and CSS too (they are text files, and, so, are generally compressed really well), and it doesn't cost much CPU either.
作为一个半旁注:你在谈论压缩HTML内容页面...但是停在HTML页面:你也可以压缩JS和CSS(它们是文本文件,因此,通常压缩得非常好),并且它不会也要花费很多CPU。
Considering the big JS/CSS Frameworks in use nowadays, the gain is probably even more consequent by compressing those than by compressing HTML pages.
考虑到现在使用的大型JS / CSS框架,通过压缩这些增益可能比压缩HTML页面更有可能。
#6
2
We made the decision to gzip all content since spending time determining what to gzip or what not to gzip did not seem worth the effort. The overhead of gzipping everything is not significantly higher than gzipping nothing.
我们决定对所有内容进行gzip,因为花时间确定gzip是什么或gzip什么不值得努力。 gzipping一切的开销并不比gzipping什么都高。
This webpage suggests:
该网页建议:
"Servers choose what to gzip based on file type, but are typically too limited in what they decide to compress. Most web sites gzip their HTML documents. It's also worthwhile to gzip your scripts and stylesheets, but many web sites miss this opportunity. In fact, it's worthwhile to compress any text response including XML and JSON. Image and PDF files should not be gzipped because they are already compressed. Trying to gzip them not only wastes CPU but can potentially increase file sizes."
“服务器根据文件类型选择gzip的内容,但是他们决定压缩的内容通常太有限了。大多数网站都会对他们的HTML文档进行gzip。也很有必要对你的脚本和样式表进行gzip,但很多网站都错过了这个机会。事实上,压缩包括XML和JSON在内的任何文本响应都是值得的。图像和PDF文件不应该被压缩,因为它们已经被压缩了。尝试gzip它们不仅浪费CPU,而且可能会增加文件大小。“
If you care about cpu time, I would suggest not gzipping already compressed content. Remember when adding complexity to a system that Programmers/sys admins are expensive, servers are cheap.
如果你关心cpu时间,我建议不要压缩已经压缩的内容。请记住,当为程序员/系统管理员付出昂贵代价的系统增加复杂性时,服务器便宜。