在. .haccess 中配置直接添加
设置了 Cache-Control 会覆盖 Expires 的过期时间
效果就是,关掉浏览器重新打开访问会读取 Cache-Control(from disk cache) 缓存 从硬盘加载, 直接刷新访问(不是强刷)的情况下会读取 from memory cache
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|woff|js|css|swf)$">
	Header set Cache-Control "max-age=31536000"
    #31536000 秒等于1年
	FileETag MTime Size
</FilesMatch>
<IfModule expires_module>
    #打开缓存
    ExpiresActive on 
    ExpiresByType text/html "access plus 12 months"
    ExpiresByType image/gif  "access plus 12 months"
    ExpiresByType image/svg  "access plus 12 months"
    ExpiresByType image/jpeg "access plus 12 months"
    ExpiresByType image/png "access plus 12 months"
    ExpiresByType text/css "now plus 12 months"
    ExpiresByType application/x-javascript "now plus 12 months"
    ExpiresByType application/x-shockwave-flash "now plus 12 months”
    #其他数据不缓存
    ExpiresDefault "now plus 0 min"
  </IfModule>
<IfModule expires_module>
# 启用有效期控制
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 image/x-icon "access plus 1 month"
# css/js
ExpiresByType text/css "access plus 4 weeks"
ExpiresByType text/javascript "access plus 4 weeks"
# html
ExpiresByType text/html "access plus 2 days"
  </IfModule>  #开启缓存
    ExpiresActive on
    #针对不同类型元素设置缓存时间
    ExpiresByType image/gif  "access plus 1 days"
    ExpiresByType image/jpeg "access plus 24 hours"
    ExpiresByType image/png "access plus 24 hours"
    ExpiresByType text/css "now plus 2 hour"
    ExpiresByType application/x-javascript "now plus 2 hours"
    ExpiresByType application/x-shockwave-flash "now plus 2 hours”
    #其他数据不缓存
    ExpiresDefault "now plus 0 min"
缓存起始点
access   从当前访问时间开始
now (equivalent to 'access')  相当于access
modification   从修改时间算起
缓存时间单位
years
months
weeks
days
hours
minutes
seconds前提要打开 这几个插件 在 httpd.conf 中:
LoadModule expires_module modules/mod_expires.so
LoadModule cache_module modules/mod_cache.so
 LoadModule cache_disk_module modules/mod_cache_disk.so
这个 开启:

在apache 中开启:

这样就 完成了.如果实在本地呢 也可以直接在 httpd.conf 中加

 
                    
                 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号