zoukankan      html  css  js  c++  java
  • cache -- clear( 缓存清除的方法)

    一:meta方法

    <META HTTP-EQUIV="pragma" CONTENT="no-cache"> 
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate"> 
    <META HTTP-EQUIV="expires" CONTENT="0">

    二:清理form表单的临时缓存 
    方式一:用ajax请求服务器最新文件,并加上请求头If-Modified-Since和Cache-Control,如下:

     $.ajax({
         url:'www.haorooms.com',
         dataType:'json',
         data:{},
         beforeSend :function(xmlHttp){ 
            xmlHttp.setRequestHeader("If-Modified-Since","0"); 
            xmlHttp.setRequestHeader("Cache-Control","no-cache");
         },
         success:function(response){
             //操作
         }
         async:false
      });

    方法二,直接用cache:false

     $.ajax({
         url:'www.haorooms.com',
         dataType:'json',
         data:{},
         cache:false, 
         ifModified :true ,
    
         success:function(response){
             //操作
         }
         async:false
      });

    方法三:用随机数,随机数也是避免缓存的一种很不错的方法!

      

    URL 参数后加上 "?ran=" + Math.random(); //当然这里参数 ran可以任意取了
    eg:
    <script> 
    document.write("<s"+"cript type='text/javascript' src='/js/test.js?"+Math.random()+"'></scr"+"ipt>"); 
    </script>
    
    其他的类似,只需在地址后加上+Math.random() 
    注意:因为Math.random() 只能在Javascript 下起作用,故只能通过Javascript的调用才可以 

    三:后端清理

      在服务端加 header("Cache-Control: no-cache, must-revalidate");等等(如php中)

  • 相关阅读:
    网站视频播放器JCPlayer
    常用Linux命令操作
    对词法分析器的了解
    实验二简化版C语言中文理解程序文法
    词法分析
    实验三有穷自动机的构造和识别
    组合数据类型练习,综合练习
    零基础初学者学习编译原理
    用python画五星红旗
    Android环境搭建和编写helloworld
  • 原文地址:https://www.cnblogs.com/yuerdong/p/8241475.html
Copyright © 2011-2022 走看看