Apache开启expires响应头,优化缓存

apache开始expires响应头输出

expires是什么

指示资源什么时候过期的时间值(GMT时间),在指定的过期时间前,浏览器可以直接使用自身缓存的版本,而不用向服务器发请求,大大减轻服务器压力.

apache设置expires

打开 http.conf 文件,做如下修改:

  1. 开启模块

     #LoadModule expires_module modules/mod_expires.so  //去掉#
    
  2. 配置各类资源的过期时间

     <IfModule expires_module>
         #打开缓存
         ExpiresActive on 
    
         #css文件缓存7200000/3600/24=83天
         ExpiresByType text/css A7200000
    
         #js文件缓存83天
         ExpiresByType application/x-javascript A7200000
         ExpiresByType application/javascript A7200000
    
         #html文件缓存83天
         ExpiresByType text/html A7200000
         
         #图片文件缓存83天
         ExpiresByType image/jpeg A7200000
         ExpiresByType image/gif A7200000
         ExpiresByType image/png A7200000
         ExpiresByType image/x-icon A7200000
    
     </IfModule>
    

验证expires开启效果

在浏览器中输入url,按回车(或者从其他页面点击跳转过来),查看网络面板资源的请求, 响应头包含 expires: Fri, 21 Oct 2016 03:29:33 GMT , status: 200 from cache 则表示expires生效

posted @ 2016-10-21 11:39  stephenykk  阅读(2881)  评论(0编辑  收藏  举报