2017-08-13 171 views
0

https://bm-translations.de我試圖通過的.htaccess激活的gzip壓縮和瀏覽器緩存:htaccess的gzip和瀏覽器緩存

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ./[L,R=301] 

# FORCE HTTPS 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://bm-translations.de/$1 [L,R=301] 

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

<IfModule mod_filter.c> 
<IfModule mod_deflate.c> 
SetOutputFilter DEFLATE 
BrowserMatch ^Mozilla/4\.0[678] no-gzip 
BrowserMatch \bMSIE\s7 !no-gzip !gzip-only-text/html 
</IfModule> 
</IfModule> 

<ifModule mod_headers.c> 
    <filesMatch "\.(ico|jpe?g|png|gif|swf)$"> 
    Header set Cache-Control "public" 
    </filesMatch> 
    <filesMatch "\.(css)$"> 
    Header set Cache-Control "public" 
    </filesMatch> 
    <filesMatch "\.(js)$"> 
    Header set Cache-Control "private" 
    </filesMatch> 
    <filesMatch "\.(x?html?|php)$"> 
    Header set Cache-Control "private, must-revalidate" 
    </filesMatch> 
</ifModule> 

<ifModule mod_expires.c> 
    ExpiresActive On 
    ExpiresDefault "access plus 1 month" 
    ExpiresByType image/x-icon "access plus 21600000 seconds" 
    ExpiresByType image/jpeg "access plus 21600000 seconds" 
    ExpiresByType image/png "access plus 21600000 seconds" 
    ExpiresByType image/gif "access plus 21600000 seconds" 
    ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds" 
    ExpiresByType text/css "access plus 21600000 seconds" 
    ExpiresByType text/javascript "access plus 21600000 seconds" 
    ExpiresByType application/javascript "access plus 216000 seconds" 
    ExpiresByType application/x-javascript "access plus 216000 seconds" 
    ExpiresByType text/html "access plus 600 seconds" 
    ExpiresByType application/xhtml+xml "access plus 600 seconds" 
</ifModule> 

出於某些原因頁高速洞察依然呈現出既沒有被激活,你可以看到這裏:https://developers.google.com/speed/pagespeed/insights/?hl=de&url=https%3A%2F%2Fbm-translations.de enter image description here

我在做什麼錯在這裏?或者是否有可能將資源上載爲gzip,或者是否會導致錯誤?

回答

1

我看到了服務器緩存延遲的實例。換句話說,識別gzip壓縮可能只是需要一些時間。以下是我的一個工作示例。

## Enable gzip compression ## 
    # compress text, HTML, JavaScript, CSS, and XML 
    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 

    # Remove browser bugs 
    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 
    ## END Enable gzip compression ## 
+0

這個作品,非常感謝你!但仍然存在緩存問題。 –

+1

這很棒,我看到該網站現在是gzipped。有關緩存,請參閱以下https://codepen.io/anon/pen/dzzBvW –