網頁啟用Gzip壓縮 提高瀏覽速度

來源:互聯網
上載者:User

標籤:獨立   href   虛擬   .com   iis   src   div   代碼   屬性   

Gzip壓縮效率非常高,通常可以達到70%的壓縮率,也就是說,如果你的網頁有30K,壓縮之後就變成了9K左右。
第一步:開啟IIS,啟用HTTP壓縮服務

右擊“網站”->“屬性”,選擇“服務”。在“HTTP壓縮”框中選中“壓縮應用程式檔案”和“ 壓縮靜態檔案”,按需要設定“臨時目錄”和“臨時目錄的最大限制”;
第二步:啟用web服務

 

第三步:修改MetaBase.xml
開始 > 運行中輸入 c:\windows\system32\inetsrv,找到 MetaBase.xml,先備份,在修改。(有的伺服器不需要修改此檔案便可以使用)
搜尋 Location ="/LM/W3SVC/Filters/Compression/gzip"
仔細核對下代碼:

<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/deflate" HcCompressionDll="%windir%\system32\inetsrv\gzip.dll" HcCreateFlags="0" HcDoDynamicCompression="TRUE" HcDoOnDemandCompression="TRUE" HcDoStaticCompression="FALSE" HcDynamicCompressionLevel="0" HcFileExtensions="htm html txt" HcOnDemandCompLevel="10" HcPriority="1" HcScriptFileExtensions="asp dll exe" > </IIsCompressionScheme> <IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/gzip" HcCompressionDll="%windir%\system32\inetsrv\gzip.dll" HcCreateFlags="1" HcDoDynamicCompression="TRUE" HcDoOnDemandCompression="TRUE" HcDoStaticCompression="TRUE" HcDynamicCompressionLevel="0" HcFileExtensions="htm html txt" HcOnDemandCompLevel="10" HcPriority="1" HcScriptFileExtensions="asp dll exe" > </IIsCompressionScheme>

替換成:

<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/gzip" HcCompressionDll="%windir%\system32\inetsrv\gzip.dll" HcCreateFlags="1" HcDoDynamicCompression="TRUE" HcDoOnDemandCompression="TRUE" HcDoStaticCompression="TRUE" HcDynamicCompressionLevel="10" HcFileExtensions="html css js htm xml txt" HcOnDemandCompLevel="10" HcPriority="1" HcScriptFileExtensions="php dll" > </IIsCompressionScheme> <IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/deflate" HcCompressionDll="%windir%\system32\inetsrv\gzip.dll" HcCreateFlags="2" HcDoDynamicCompression="TRUE" HcDoOnDemandCompression="TRUE" HcDoStaticCompression="TRUE" HcDynamicCompressionLevel="10" HcFileExtensions="html css js htm xml txt" HcOnDemandCompLevel="10" HcPriority="1" HcScriptFileExtensions="php dll" > </IIsCompressionScheme>

修改好後,在服務中停止IIS Admin Service 服務

然後在儲存MeteBase.xml,儲存好後再啟動IIS。這樣Gzip壓縮就啟用成功了。

最後,測試Gzip壓縮是否成功,可以到站長工具http://tool.chinaz.com/Gzips/進行檢測。

提示:

本文僅針對windows的IIS伺服器上示範的,VPS主機、獨立伺服器均可以實現,虛擬機器主機使用者需要諮詢空間商(一般虛擬機器主機都啟用了Gzip)如果你的站在啟用Gzip壓縮時遇到了困難,可在此跟帖評論與交流,我會竭盡全力為大家解答。

 

網頁啟用Gzip壓縮 提高瀏覽速度

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.