压缩页面以使其加载速度更快
有没有办法压缩 html 页面或 asp.net 页面的 html 输出,使它们加载得更快。 我听说谷歌正在以某种方式使用该技术。
提前致谢。
Is there any way to compress an html page or html output of asp.net page to make them load faster. I heard that Google is using that technology someway.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
当然可以打开 http 压缩来减少通过网络传输的数据的大小,并且所有现代浏览器都知道如何解压缩响应。 由于传输的数据较少,它只会缩短加载时间。 如果这不是瓶颈所在,您可能看不到您希望的改进。 如果您正在寻找提高网页性能的其他方法,您可能还需要查看 YSlow 或 Page Speed 等工具。
It's certainly possible to turn on http compression to reduce the size of the data transmitted over the network and all modern browsers will know how to unzip the response. It only improves the load time due to less data being transferred though. If that's not where the bottleneck is, you may not see the improvement you're hoping for. You may also want to look at tools like YSlow or Page Speed if you're looking for other ways of improving the performance of a web page.
是的,以
Content-Encoding: gzip
形式交付页面可能会更快地将页面本身交付给浏览器。 但是,如果真正的问题是用户认为页面加载缓慢,则您需要记住显示页面的过程有几个部分,而您只查看其中的一个部分。 加载页面本身的 HTML 后,浏览器仍然必须解析它,开始执行页面中的任何脚本,并加载页面所需的任何其他数据(例如图像)。 最后一部分花费大量时间通常会导致页面显示缓慢。Yes, delivering the page as
Content-Encoding: gzip
will probably deliver the page itself to the browser more quickly. But if the real problem is that the page appears to the user to load slowly, you need to remember that the process of displaying the page has several parts, of which you're looking at only one. After loading the HTML for the page itself, the browser still has to parse it, start executing any scripts in the page, and load any further data (such as images) that the page requires. This last part taking a lot of time is often what makes a page appear to display slowly.您可以在 IIS 6/7 中使用 HTTP 压缩。 请参阅 http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d52ff289-94d3-4085-bc4e-24eb4f312e0e.mspx?mfr=true 或者您可以查看缓存您的 ASPX 页面,请参阅到 https://web .archive.org/web/20211020111708/https://www.4guysfromrolla.com/articles/121306-1.aspx
You can use HTTP Compression in IIS 6/7. Refer to http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d52ff289-94d3-4085-bc4e-24eb4f312e0e.mspx?mfr=true or you could look at caching your ASPX page, refer to https://web.archive.org/web/20211020111708/https://www.4guysfromrolla.com/articles/121306-1.aspx
如果您使用的是 iis 6,这里有一个非常简单的启用压缩的方法。
http://lunarmedia.com/blogs/lunarmedia_blog/archive/2007/11/05/iis6-http-compression-quick-and-easy-four-steps.aspx
If you are using iis 6 here is a really easy way to enable compression.
http://lunarmedia.com/blogs/lunarmedia_blog/archive/2007/11/05/iis6-http-compression-quick-and-easy-four-steps.aspx
另一种非 IIS 特定的方法是测量页面的哪些部分加载时间最长。
Yahoo! 的 yslow 是一个不错的免费工具
您还可以尝试使用 pngcrush 等工具或在线实用程序 smush-it
如果您使用了大量 CSS,您可以使用 CSSTidy 将其最小化。
Another, non IIS specific approach is to measure what parts of your page are taking the most time to load.
A good and free tool is yslow from Yahoo!
You can also try to optimize your image files with tools like pngcrush or the online utility smush-it
If you are using a lot of CSS you can minimize it with CSSTidy.
我知道您使用的是 asp.net,但是对于遇到此问题并使用 apache 的任何人来说,最好的(最快、占用 CPU 资源最少)的压缩方法是 mod_deflate, 。
这就是我在 .htaccess 中使用的:
来源:http://httpd。 apache.org/docs/2.0/mod/mod_deflate.html
并有证据表明它更快:http://www.google.co.uk/search?q=deflate+vs+gzip
I know your using asp.net, but for anyone who comes across this and is using apache, the best (fastest, least cpu intensive) method of compression is mod_deflate, .
This is what I use in my .htaccess:
Source: http://httpd.apache.org/docs/2.0/mod/mod_deflate.html
And for evidence that it is faster: http://www.google.co.uk/search?q=deflate+vs+gzip
在 google 上搜索术语“gzip”
Do a google search for the term "gzip"