• 静态的html页面想要设置使用浏览器缓存


    设置html页面缓存方法:

    静态的html页面想要设置使用缓存:

    通过HTTP的META设置expires和cache-control 
    code
    1.  <meta http-equiv="Cache-Control" content="max-age=7200" />
    2.  <meta http-equiv="Expires" content="Mon, 20 Jul 2013 23:00:00 GMT" />
     
    上述设置仅为举例,实际使用其一即可。这样写的话仅对该网页有效,对网页中的图片或其他请求无效,并不会做任何cache。 参数说明: max-age 指示客户机可以接收生存期不大于指定时间(以秒为单位)的响应。 Expires 表示存在时间,允许客户端在这个时间之前不去检查(发请求),等同max-age的 效果。但是如果同时存在,则被Cache-Control的max-age覆盖。 Expires: Thu, 01 Dec 1994 16:00:00 GMT (必须是GMT格式)
     
     

    要在后台代码段,实现图片,css,js,flash的缓存

    Response.AddHeader("cache-control","max-age=时间(单位:秒)")或Response.Expires=时间(单位:分)来启用缓存。如果用Response.AddHeader("expires","utc时刻")来设置Expires的话,cache-control的优先级比expires高,

    就是说如果设置了cache-control,那么expires设置的值就被覆盖掉。如果是用Response.Expires设置的话就不受这个约束。

    对网页中的图片或其他请求服务器端缓冲设置
    apache静态文件缓存时间设置
    如果要对文件添加cache可以通过apache的mod_expire模块,写法为  


    关于图片,css,js,flash的缓存

    这个主要通过服务器的配置来实现这个技术,如果使用apache服务器的话,可以使用mod_expires模块来实现:

    编译mod_expires模块:

    Cd  /root/httpd-2.2.3/modules/metadata

    /usr/local/apache/bin/apxs -i -a -c mod_expires.c //编译

    先打开httpd.conf文件,然后查找expires这个模块,找到后,删除左边的#号,表示打这个模块,并重启apache服务器

    编辑httpd.conf配置:添加下面内容

    <IfModule mod_expires.c>

    ExpiresActive on

    ExpiresDefault "access plus 1 month"

    ExpiresByType text/html "access plus 1 months"

    ExpiresByType text/css "access plus 1 months"

    ExpiresByType image/gif "access plus 1 months"

    ExpiresByType image/jpeg "access plus 1 months"

    ExpiresByType image/jpg "access plus 1 months"

    ExpiresByType image/png "access plus 1 months"

    EXpiresByType application/x-shockwave-flash "access plus 1 months"

    EXpiresByType application/x-javascript      "access plus 1 months"

    #ExpiresByType video/x-flv "access plus 1 months"

    </IfModule>

    解释:第一句--开启服务

    第二句--默认时间是一个月

    在下面是关于各种类型的资源的缓存时间设置

    更详细的说明可以参考我的《网站优化--让你的网页飞起来》关于这个模块的使用介绍

    参考资料:http://www.infoq.com/cn/articles/etags

                     http://www.lifetyper.com/archives/000087.html
                     http://developer.yahoo.com/performance/rules.html
                     http://www.websiteoptimization.com/speed/tweak/cache/

                      http://www.mnot.net/cache_docs/




  • 相关阅读:
    Hadoop3.0时代,怎么能不懂EC纠删码技术?| 个推技术实践
    linux系统安装mysql
    集合随机排序,list随机排序
    linux性能调优、内存、cpu使用相关命令
    java获取方法调用类
    移动云采用xshell连接
    nginx操作命令
    linux下mysql8版本修改登录密码
    登录验证码图片
    sudo: aptget: command not found
  • 原文地址:https://www.cnblogs.com/MrZouJian/p/5573326.html
Copyright © 2020-2023  润新知