針對 Apache 和 Nginx 進行頻寬最佳化
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
2014年9月23日星期二
原文:
Optimizing for Bandwidth on Apache and Nginx
作者:Jeff Kaufman
減少頻寬使用量是大家共同的願望,因為不僅業主希望藉此減少帳單費用,行動使用者也希望頻寬使用量保持在限制之下,
沒有人想為不必要的位元組浪費等待時間。網路上處處有可以節省頻寬的地方,比如未使用 GZIP 或樣式表的網頁、所用 JavaScript 尚未縮小的網頁、尚未最佳化的圖片等等,這些還只是一部分而已。
既然減少頻寬消耗對人人有益,為什麼現今的網路環境仍未有效運用頻寬、還有許多未改進的地方呢?主要是因為這太過麻煩。雖然網頁設計師在匯出作品時會選擇「Save for web」,但他們有時會忘記這件事情。JavaScript 程式設計師也不愛處理縮小的程式碼,因為這會增加偵錯的困難度。雖然只要建立自訂管道,就能確保在開發及部署的過程中持續為網站套用這些最佳化措施,但實在工程浩大。
對於網路使用者而言,最簡單的解決辦法就是使用最佳化 Proxy,例如
Chrome
的 Proxy。使用者啟用這項服務後,系統便會透過 Google 的 Proxy 傳送他們的 HTTP 流量,進而獲得最佳化網頁載入速度,並減少 50% 的頻寬用量。雖然 Chrome 使用者開啟這項功能即可享受迅捷速度,但是其他使用者仍得面臨相同處境,這個做法也不適用於 HTTPS 流量。
為此,PageSpeed 小組特別製作了
頻寬最佳化
網頁,希望各位網站管理員都能運用這裡的技術造福大眾,包括其他瀏覽器或安全站台的使用者、桌機使用者,以及眾多渴望減少輸出流量費用的網站擁有者。只要在 Apache 或 Nginx 伺服器上安裝
PageSpeed 模組
[1],然後在設定中
開啟
頻寬最佳化,PageSpeed 就會接手完成所有動作。
[1] 如果您使用的是其他網路伺服器,建議您在 Apache 或 Nginx Proxy 上執行 PageSpeed。本工具完全
開放原始碼
,目前正在移植到
IIS
、
ATS
和其他平台。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2014-09-01 (世界標準時間)。
[null,null,["上次更新時間: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."]]