zoukankan      html  css  js  c++  java
  • 清除浏览器页面缓存

    比如注册是当浏览器第一次注册成功后,并进行回退到原注册页面再次修改内容并地二次提交,此时的二次提交的内容是

    缓存内容,所以要将缓存内容清空后才能生效,清空缓存的方法:

    Using PHP:

    header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
    header("Pragma: no-cache"); // HTTP 1.0.
    header("Expires: 0"); // Proxies.

    Using Java Servlet, or Node.js:

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    response.setHeader("Expires", "0"); // Proxies.

    Using ASP.NET:

    Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
    Response.AppendHeader("Expires", "0"); // Proxies.

    Using ASP:

    Response.addHeader "Cache-Control", "no-cache, no-store, must-revalidate" ' HTTP 1.1.
    Response.addHeader "Pragma", "no-cache" ' HTTP 1.0.
    Response.addHeader "Expires", "0" ' Proxies.

    Using Ruby on Rails, or Python on Flask:

    response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate" # HTTP 1.1.
    response.headers["Pragma"] = "no-cache" # HTTP 1.0.
    response.headers["Expires"] = "0" # Proxies.

    Using Google Go:

    responseWriter.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") // HTTP 1.1.
    responseWriter.Header().Set("Pragma", "no-cache") // HTTP 1.0.
    responseWriter.Header().Set("Expires", "0") // Proxies.

    Using Apache .htaccess file:

    <IfModule mod_headers.c>
        Header set Cache-Control "no-cache, no-store, must-revalidate"
        Header set Pragma "no-cache"
        Header set Expires 0
    </IfModule>

    Using HTML4:

    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    

    HTML meta tags vs HTTP response headers

    根据SO上面的说法,

    如果通过HTTP访问,HTTP response headers 是优先于 meta tags 的。但

    是,第一次打开是通过HTTP访问的,而返回的时候是从本地读取的。

     
    我在自己尝试的时候,发现这两个都需要设置 才能清除页面表单记录。Google浏览器 和 IE11测试通过,页面的记录消除。其他的浏览器未测试。(推测是因为上面的原因)
    如果多次测试发现 页面表单的记录还在。
     
    但是可以保证,只要写了HTTP response headers 返回的时候一定会重新请求。
     1 <%@ page language="java" contentType="text/html; charset=UTF-8"
     2     pageEncoding="UTF-8"%>
     3 <%  
     4 response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.  
     5 response.setHeader("Pragma", "no-cache"); // HTTP 1.0.  
     6 response.setHeader("Expires", "0"); // Proxies.  
     7 %> 
     8 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     9 <html>
    10 <head>
    11 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    12 <title>Insert title here</title>
    13     <!-- <meta http-equiv="pragma" content="no-cache">  
    14     <meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate" >  
    15     <meta http-equiv="expires" content="0" > --> 
    16 </head>
    17 <body>
    18 <%  
    19            long token=System.currentTimeMillis();    //产生时间戳的token
    20             session.setAttribute("token",token);      
    21     %>  
    22 
    23     <form  action="${pageContext.servletContext.contextPath }/formSubmit/submit_.action" method="post">  
    24         <input type="text"  name="username"/>  <br>
    25         <input type="text"  name="password"/>  <br>  
    26         <input type="hidden" value="${token }" name="reqtoken"/>  <br>   <!-- 作为hidden提交 -->  
    27         <input type="submit" value="提交"/>  <br>  
    28     </form>  
    29 </body>
    30 </html>
  • 相关阅读:
    团队会议第八天
    团队会议第七天
    站立会议第五天
    站立会议第四天
    站立会议第三天
    站立会议第二天
    站立会议第一天(2016.4.19)
    团队报告
    团队计划backlog
    每日Scrum(5)
  • 原文地址:https://www.cnblogs.com/lubolin/p/7462692.html
Copyright © 2011-2022 走看看