简体   繁体   English

htaccess gzip和浏览器缓存

[英]htaccess gzip and browser caching

On https://bm-translations.de I am trying to activate gzip compress and browser caching via .htaccess: https://bm-translations.de上,我尝试通过.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>

Out of some reasons Page-Speed Insights is still showing both is not activated as you can see here: https://developers.google.com/speed/pagespeed/insights/?hl=de&url=https%3A%2F%2Fbm-translations.de 出于某些原因,Page-Speed Insights仍显示两者均未激活,如下所示: https : //developers.google.com/speed/pagespeed/insights/?hl=de&url=https%3A%2F%2Fbm- translations.de 在此处输入图片说明

What am I doing wrong here? 我在这里做错了什么? Or is it possible to upload the ressources as gzip already instead or will this cause errors somewhere? 还是有可能已经将资源以gzip的形式上传,还是会在某处导致错误?

I have seen instances of cache delay from server. 我看到了服务器延迟缓存的实例。 In other words, it might just take time to recognize gzip compression. 换句话说,识别gzip压缩可能只需要一些时间。 Below is a working example of mine. 以下是我的一个工作示例。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM