让浏览器缓存CSS、JS、图片、静态文件等是很重要的事情,这样可以减轻服务器的压力,省的浏览器经常要去服务端下载这些静态文件。下面看看配置方法吧。
1.开启apache扩展模块mod_expires.so,在apache的配置文件中加入下面一行代码。
LoadModule expires_module modules/mod_expires.so
2.配置缓存,在apache配置文件中加入下面一段代码
<IfModule expires_module>
 

   #打开缓存
    ExpiresActive on 
    #css文件缓存7200000/3600/24=83天
    ExpiresByType text/css A7200000
    #js文件缓存7200000/3600/24=83天
    ExpiresByType application/x-javascript A7200000
    ExpiresByType application/javascript A7200000
    #html文件缓存7200000/3600/24=83天
    ExpiresByType text/html A7200000
    #图片文件缓存7200000/3600/24=83天
    ExpiresByType image/jpeg A7200000
    ExpiresByType image/gif A7200000
    ExpiresByType image/png A7200000
    ExpiresByType image/x-icon A7200000
</IfModule>
3.测试
访问有图片,css,js,html的文件
http://localhost:8080/test/test.html
用firebug可以看到响应头信息包含
Expires Tue, 13 Sep 2011 15:41:09 GMT
Cache-Control max-age=7200000

如何把不配置缓存,上面的头信息就没有,哈哈,试试吧 。

相关文章:

  • 2021-09-27
  • 2022-02-08
  • 2021-06-01
  • 2021-11-19
  • 2021-09-01
  • 2021-11-17
  • 2022-12-23
  • 2021-12-26
猜你喜欢
  • 2022-12-23
  • 2021-11-11
  • 2021-10-11
  • 2021-09-29
  • 2021-05-21
  • 2022-12-23
  • 2021-09-07
相关资源
相似解决方案