2017-07-04 146 views

回答

1

www.checkgzipcompression.com即使GZIP僅針對單一文件類型啓用,僅當Pingdom和GTMetrix等pagespeed工具希望您爲所有文件類型集成GZIP壓縮時,纔會計數GZIP啓用。

您可以手動啓用GZIP壓縮,方法是更新.htaccess或使用一個插件,該插件將爲您執行相同的操作,但具有用戶友好的用戶界面。

如果要手動啓用GZIP壓縮,請將以下代碼添加到您的WP根目錄中的.htaccess文件中。

<IfModule mod_deflate.c> 
    # Compress HTML, CSS, JavaScript, Text, XML and fonts 
    AddOutputFilterByType DEFLATE application/javascript 
    AddOutputFilterByType DEFLATE application/rss+xml 
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject 
    AddOutputFilterByType DEFLATE application/x-font 
    AddOutputFilterByType DEFLATE application/x-font-opentype 
    AddOutputFilterByType DEFLATE application/x-font-otf 
    AddOutputFilterByType DEFLATE application/x-font-truetype 
    AddOutputFilterByType DEFLATE application/x-font-ttf 
    AddOutputFilterByType DEFLATE application/x-javascript 
    AddOutputFilterByType DEFLATE application/xhtml+xml 
    AddOutputFilterByType DEFLATE application/xml 
    AddOutputFilterByType DEFLATE font/opentype 
    AddOutputFilterByType DEFLATE font/otf 
    AddOutputFilterByType DEFLATE font/ttf 
    AddOutputFilterByType DEFLATE image/svg+xml 
    AddOutputFilterByType DEFLATE image/x-icon 
    AddOutputFilterByType DEFLATE text/css 
    AddOutputFilterByType DEFLATE text/html 
    AddOutputFilterByType DEFLATE text/javascript 
    AddOutputFilterByType DEFLATE text/plain 
    AddOutputFilterByType DEFLATE text/xml 

    # Remove browser bugs (only needed for really old browsers) 
    BrowserMatch ^Mozilla/4 gzip-only-text/html 
    BrowserMatch ^Mozilla/4\.0[678] no-gzip 
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
    Header append Vary User-Agent 
</IfModule> 

上述代碼適用於Apache服務器。如果你是NGINX服務器上,使用此代碼,而不是在nginx.conf文件:

gzip on; 
gzip_disable "MSIE [1-6]\.(?!.*SV1)"; 
gzip_vary on; 
gzip_types text/plain text/css text/javascript image/svg+xml image/x-icon application/javascript application/x-javascript; 

現在,GZIP壓縮可與許多緩存插件啓用,流行它們是W3 Total Cache。檢查這article關於如何設置W3總緩存和它的GZIP壓縮模塊。

Code Source