zoukankan      html  css  js  c++  java
  • apache下用expires_module让浏览器缓存静态文件

    让浏览器缓存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

    如何把不配置缓存,上面的头信息就没有,哈哈,试试吧 。
  • 相关阅读:
    黑盒测试实践——每日例会记录(一)
    《高级软件测试》—如何计算团队成员贡献分
    TestLink学习——第一周使用小结
    BugkuCTF 你必须让他停下
    BugkuCTF 域名解析
    BugkuCTF web3
    BugkuCTF 矛盾
    BugkuCTF web基础$_POST
    BugkuCTF web基础$_GET
    BugkuCTF 计算器
  • 原文地址:https://www.cnblogs.com/yuanzai12345/p/5946728.html
Copyright © 2011-2022 走看看