简体   繁体   English

Gzip压缩和缓存过期无效

[英]Gzip compression and cache expiration not working

I have configured cache expiration and gzip compression in .htaccess file but its not working according to yslow chrome extension stats. 我已经在.htaccess文件中配置了缓存过期和gzip压缩,但它根据yslow chrome扩展统计信息无法正常工作。

Here is my .htaccess 这是我的.htaccess

# ----------------------------------------------------------------------
# Mod Rewrite
# ----------------------------------------------------------------------

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

# ----------------------------------------------------------------------
# gZip Compression
# ----------------------------------------------------------------------

<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 headers (for better cache control)
# ----------------------------------------------------------------------

<IfModule mod_expires.c>
  ExpiresActive on

# Your document html
  ExpiresByType text/html "access plus 0 seconds"

# Media: images, video, audio
  ExpiresByType audio/ogg "access plus 1 month"
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType video/mp4 "access plus 1 month"
  ExpiresByType video/ogg "access plus 1 month"
  ExpiresByType video/webm "access plus 1 month"

# CSS and JavaScript
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType text/css "access plus 1 year"
</IfModule>

Note: I'm using Xampp 注意:我正在使用Xampp

This is my first post here! 这是我第一次发帖!

For cache expiration: 对于缓存过期:

Did you check if the module "mod_expires.so" is enabled in apache/conf/httpd.conf? 您是否检查过apache / conf / httpd.conf中是否启用了模块“mod_expires.so”? Search for the line #LoadModule expires_module modules/mod_expires.so and remove the "#" sign. 搜索#LoadModule expires_module modules/mod_expires.so并删除“#”符号。 After that it should work. 之后它应该工作。

For gzip compression: 对于gzip压缩:

I use "mod_deflate" to enable compression. 我使用“mod_deflate”来启用压缩。 I also use "mod_mime", "mod_setenvif" and "mod_headers". 我还使用“mod_mime”,“mod_setenvif”和“mod_headers”。 Check each be enabled in httpd.conf. 检查每个都在httpd.conf中启用。 This combination works for me. 这种组合对我有用。

Htaccess my compression: Htaccess压缩:

<IfModule mod_mime.c>
 AddType application/x-javascript .js
 AddType text/css .css
</IfModule>

<IfModule mod_deflate.c>
 SetOutputFilter DEFLATE
 <IfModule mod_setenvif.c>
  SetEnvIfNoCase Request_URI \.(?:rar|zip)$ no-gzip dont-vary
  SetEnvIfNoCase Request_URI \.(?:gif|jpg|png)$ no-gzip dont-vary
  SetEnvIfNoCase Request_URI \.(?:avi|mov|mp4)$ no-gzip dont-vary
  SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
 </IfModule>
 <IfModule mod_setenvif.c>
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
 </IfModule>
 <IfModule mod_headers.c>
  Header append Vary User-Agent env=!dont-vary
 </IfModule>
</IfModule>

More information here . 更多信息在这里 I hope that helps. 我希望有所帮助。

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

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