2015-05-19 23 views
2

目標

我是新來的壓縮世界。 我想爲我的網站啓用gzip壓縮。我不確定如何以正確的方式完成。如何在我的網站上啓用Gzip並進行測試?


我已經試過

  • root/目錄我的網站創建.htaccess並添加這些行:

    AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript


使用測試卷曲

我試圖運行curl -I -H 'Accept-Encoding: gzip,deflate' http://my-site.com

結果:

% Total % Received % Xferd Average Speed Time Time  Time Current 
           Dload Upload Total Spent Left Speed 
    0 20 0  0 0  0  0  0 --:--:-- 0:00:30 --:--:--  0 
Content-Encoding: gzip 

注意:內容編碼:gzip


測試使用gzip測試在線工具

我去這個網站和en我的網址。

http://checkgzipcompression.com/?url=http%3A%2F%2Fwww.bunlongheng.com%2F

結果:You're blessed! It's GZIP Enabled.

我也上測試:https://www.feedthebot.com/tools/gzip/

結果:Gzip已工作? Yes 71.6%


瀏覽器減少文件大小

我已經試過上:Safari瀏覽器,火狐和Chrome。

通過2次測試後,我想,我做得對,但是當我去我的網站:我的風格都搞砸了。隨意看看吧:here

我的控制檯不斷給我這個錯誤:

無法加載資源:淨:: ERR_CONTENT_DECODING_FAILED


能有人請解釋這是爲什麼發生?

我需要在我的php.ini中配置任何東西嗎? 如果是這樣,我可能需要創建一個,因爲我沒有。

任何幫助將非常感激。

+0

如果你沒有得到一些回覆,你可能要使用問題底部的'flag'鏈接,並要求版主將此Q移至http://webmasters.stackexchange.com/。祝你好運。 – shellter

回答

0

我假設你使用的是Apache Web服務器。你要添加到您的.htaccess這些行:

<ifModule mod_gzip.c> 
mod_gzip_on Yes 
mod_gzip_dechunk Yes 
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$ 
mod_gzip_item_include handler ^cgi-script$ 
mod_gzip_item_include mime ^text/.* 
mod_gzip_item_include mime ^application/x-javascript.* 
mod_gzip_item_exclude mime ^image/.* 
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* 
</ifModule> 

要檢查是否Gzip已激活,您可以使用此工具: https://www.feedthebot.com/tools/gzip/

+0

我也試過,但它也沒有工作。我應該聯繫我的主機提供商嗎?我創建了'.htaccess'我的自我。我想這樣做嗎? – ihue

+0

但是當我測試我的URL時,我認爲它是正面的。 – ihue

+0

您的主機提供商是否有可能禁用此功能。這可以在php.ini中配置加上幾行: ' output_buffering =關 output_handler = 要用zlib.output_compression =關 ' – dpalmero

相關問題