繁体   English   中英

Gzip压缩和缓存过期无效

[英]Gzip compression and cache expiration not working

我已经在.htaccess文件中配置了缓存过期和gzip压缩,但它根据yslow chrome扩展统计信息无法正常工作。

这是我的.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>

注意:我正在使用Xampp

这是我第一次发帖!

对于缓存过期:

您是否检查过apache / conf / httpd.conf中是否启用了模块“mod_expires.so”? 搜索#LoadModule expires_module modules/mod_expires.so并删除“#”符号。 之后它应该工作。

对于gzip压缩:

我使用“mod_deflate”来启用压缩。 我还使用“mod_mime”,“mod_setenvif”和“mod_headers”。 检查每个都在httpd.conf中启用。 这种组合对我有用。

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>

更多信息在这里 我希望有所帮助。

暂无
暂无

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

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