优化Apache和Nginx服务器的带宽
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
2014年9月23日星期二
原文:
Optimizing for Bandwidth on Apache and Nginx
作者:Jeff Kaufman
每个人都希望节省带宽:托管服务提供商希望能够降低费用,而移动用户则不希望超出套餐流量,
没有人愿意在不需要的内容上浪费时间和带宽。网络上可节省带宽的地方比比皆是,随意就能举出几个例子:未经过gzip压缩的网页、未经过合并压缩的样式表和JavaScript以及未经优化的图片等。
那么,为什么网络没有针对带宽进行优化呢?如果节省带宽对每个人都有好处,为什么这些问题依然存在?很大程度上,这要归结为麻烦太多。我们鼓励网络设计师在导出作品时选择“另存为网页”格式,但他们有时会忽略这一点。JavaScript程序设计人员不喜欢使用经过合并压缩的代码,因为这会增加调试的难度。您可以设置自定义管道,以确保每一项这样的优化每次都可以作为开发或部署流程的一部分应用到您的网站,但这项工作相当艰巨。
网络用户可使用优化代理(如
Chrome
的代理)来轻松解决这一问题。当用户选择启用该服务时,其HTTP流量便会通过Google的代理传输,而该代理会优化网页加载并将带宽的使用量减少50%。虽然此方法对这类用户非常有用,但它仅适用于使用Chrome并启用了此功能的用户,而且不能优化HTTPS流量。
借助针对带宽进行优化
功能,PageSpeed小组将这种技术同样也提供给了网站站长,以便每个人都能从中获益:其中包括使用其他浏览器的用户、安全网站、桌面设备用户和想要降低出站流量支出的网站所有者。您只需在Apache或Nginx服务器上安装
PageSpeed模块
[1],然后
启用
配置中的“针对带宽进行优化”功能,PageSpeed就会为您搞定一切。
[1] 如果您使用的是其他网络服务器,可考虑在Apache或Nginx代理上运行PageSpeed。它完全
开放源代码
,并且我们正在努力开发针对
IIS
、
ATS
等服务器的移植功能。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2014-09-01。
[null,null,["最后更新时间 (UTC):2014-09-01。"],[[["\u003cp\u003eThe PageSpeed optimization tool helps reduce bandwidth usage by automatically optimizing website elements like images, stylesheets, and JavaScript files.\u003c/p\u003e\n"],["\u003cp\u003ePageSpeed offers an "Optimize for Bandwidth" feature, similar to Chrome's data compression proxy, to reduce bandwidth for all users, including those on different browsers and secure sites.\u003c/p\u003e\n"],["\u003cp\u003eWebsite owners can easily install the PageSpeed module on their Apache or Nginx servers and enable the "Optimize for Bandwidth" feature to benefit from these optimizations.\u003c/p\u003e\n"],["\u003cp\u003eBeyond basic bandwidth optimization, PageSpeed offers advanced features such as cache extension, inlining, image lazyloading, and deferred JavaScript execution, which can be enabled as needed.\u003c/p\u003e\n"],["\u003cp\u003ePageSpeed is open source and available for various web servers, with ongoing efforts to support even more platforms.\u003c/p\u003e\n"]]],["Webmasters can reduce bandwidth usage for all users by installing the PageSpeed module on their Apache or Nginx server. This module, with the \"Optimize for Bandwidth\" feature enabled, automatically optimizes pages, similar to Chrome's optimizing proxy. This solution benefits all browsers, secure sites, and desktop users, reducing outbound traffic. The module can be configured for more advanced optimizations like cache extension, inlining, lazyloading, and deferring JavaScript. PageSpeed is also open-source, and porting efforts are underway for other web servers.\n"],null,["# Optimizing for Bandwidth on Apache and Nginx\n\nThursday, September 04, 2014\n\n\nEveryone wants to use less bandwidth: hosts want lower bills, mobile users want to stay under\ntheir limits, and no one wants to wait for unnecessary bytes. The web is full of opportunities to\nsave bandwidth: pages served without gzip, stylesheets and JavaScript served unminified, and\nunoptimized images, just to name a few.\n\n\nSo why isn't the web already optimized for bandwidth? If these savings are good for everyone then\nwhy haven't they been fixed yet? Mostly it's just been too much hassle. Web designers are\nencouraged to \"save for web\" when exporting their artwork, but they don't always remember.\nJavaScript programmers don't like working with minified code because it makes debugging harder.\nYou can set up a custom pipeline that makes sure each of these optimizations is applied to your\nsite every time as part of your development or deployment process, but that's a lot of work.\n\n\nAn easy solution for web users is to use an optimizing proxy, like\n[Chrome's](https://developer.chrome.com/multidevice/data-compression).\nWhen users opt into this service their HTTP traffic goes via Google's proxy, which optimizes their\npage loads and cuts bandwidth usage by 50%. While this is great for these users, it's limited to\npeople using Chrome who turn the feature on and it can't optimize HTTPS traffic.\n\n\nWith\n[Optimize for Bandwidth](/speed/pagespeed/module/optimize-for-bandwidth),\nthe PageSpeed team is bringing this same technology to webmasters so that everyone can benefit:\nusers of other browsers, secure sites, desktop users, and site owners who want to bring down their\noutbound traffic bills. Just install the\n[PageSpeed module](/speed/pagespeed/module)\non your Apache or Nginx server^[1](#1)^,\n[turn on](/speed/pagespeed/module/optimize-for-bandwidth)\nOptimize for Bandwidth in your configuration, and PageSpeed will do the rest.\n\n\nIf you later decide you're interested in PageSpeed's more advanced optimizations, from\n[cache extension](/speed/pagespeed/module/filter-cache-extend)\nand\n[inlining](/speed/pagespeed/module/filter-js-inline)\nto the more aggressive\n[image lazyloading](/speed/pagespeed/module/filter-lazyload-images)\nand\n[defer JavaScript](/speed/pagespeed/module/filter-js-defer),\nit's just a matter of enabling them in your PageSpeed configuration.\n\n\nLearn more about\n[installing PageSpeed](/speed/pagespeed/module) or\n[enabling Optimize for Bandwidth](/speed/pagespeed/module/optimize-for-bandwidth).\n\nPosted by Jeff Kaufman, Make the Web Fast\n\n\n1: If you're using a different web server, consider running PageSpeed on an\nApache or Nginx proxy. And it's all\n[open source](https://github.com/apache/incubator-pagespeed-mod),\nwith porting efforts underway for\n[IIS](https://www.iispeed.com/),\n[ATS](https://www.atspagespeed.com/), and others."]]