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中)

  • 相关阅读:
    android studio 开发环境配置
    解决 php-cgi 启动时提示缺少 msvcr110.dll 的问题
    PHP5.5 + IIS + Win7的配置
    PHP版本VC6和VC9、Non Thread Safe和Thread Safe的区别
    [6]Telerik TreeView 复选框
    详解.NET IL代码(一)
    第三章 续:时间控件(TimePicker)
    第二章 时间控件(DateTime Picker)
    jquery常用方法
    RESTClient
  • 原文地址:https://www.cnblogs.com/yuerdong/p/8241475.html
Copyright © 2011-2022 走看看