首页 > Web开发 > 详细

httpd之静态缓存

时间:2016-06-06 09:11:02      阅读:237      评论:0      收藏:0      [点我收藏+]
静态缓存:用户访问一个站点,大多数元素为图片、js、css,这些文件会被客户端的浏览器缓存到本地的电脑上,加快了用户体验,但有一定的时效性。
方式1、mod_expires模块实现
 <IFModule mod_expires.c>
        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/javascript "now plus 2 hours"
        ExpiresByType application/x-shockwave-flash "now plus 2 hours"
        ExpiresDefault "now plus 0 min"
   </IfModule>

方式2、mod_headers 模块实现
<ifmodule mod_headers.c>
    # htm,html,txt 类的文件缓存一个小时
    <filesmatch "\.(html|htm|txt)$">
        header set cache-control "max-age=3600"
    </filesmatch>

    # css, js, swf 类的文件缓存一个星期
    <filesmatch "\.(css|js|swf)$">
        header set cache-control "max-age=604800"
    </filesmatch>

    # jpg,gif,jpeg,png,ico,flv,pdf 等文件缓存一年
    <filesmatch "\.(ico|gif|jpg|jpeg|png|flv|pdf)$">
        header set cache-control "max-age=29030400"
    </filesmatch>
</ifmodule>




httpd之静态缓存

原文:http://hiyang.blog.51cto.com/10728919/1786425

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!