2017-06-06 97 views
0

我對緩存wp站點了解不多。我正在使用超高速緩存,它正在工作,但頁速率工具顯示該網站運行在44/100。如果我壓縮一些js和css文件,在啓用壓縮下它說我可以將傳輸大小減少70%。它看起來不像SuperCache提供壓縮或緩存特定文件的選項,所以我的問題就是這樣。如何壓縮和緩存某些不受SuperCache影響的js和css文件?如何緩存js,css和圖像

回答

0

要壓縮的文件(JS,CSS等),你需要把下面的代碼.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> 

要高速緩存圖像,

## EXPIRES CACHING ## 
<IfModule mod_expires.c> 
ExpiresActive On 
ExpiresByType image/jpg "access plus 1 month" 
ExpiresByType image/jpeg "access plus 1 month" 
ExpiresByType image/gif "access plus 1 month" 
ExpiresByType image/png "access plus 1 month" 
ExpiresByType text/css "access plus 1 month" 
ExpiresByType application/pdf "access plus 1 month" 
ExpiresByType text/x-javascript "access plus 1 month" 
ExpiresByType application/x-shockwave-flash "access plus 1 month" 
ExpiresByType image/x-icon "access plus 1 month" 
ExpiresDefault "access plus 7 days" 
</IfModule> 
## EXPIRES CACHING ## 

要放氣,

<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> 

將此全部添加到.htaccess文件中,它將增加頁面速度結果。