JS Clear Browser Cache

Source: Internet
Author: User
Tags browser cache clear browser cache

Browser cache
    1. All the data can be stored in the server, but this is not efficient, when we visit the Web page, one will be Dayton, two will waste the server storage space, three will cause pressure on the server
    2. Browser caching can improve site performance and browser speed, but for Web pages that require frequent updates, caching prevents users from displaying the updated style
How to clear the cache via JS?

Random number

    1. The script does not exist, but is dynamically generated by the server, so it has a version number to show the difference. The random number after the path or file name is equivalent to the file, but the browser thinks he is a version of the file!
    2. The client will cache these CSS or JS files, so each time you upgrade the JS or CSS file, change the version number, the client browser will re-download the new JS or CSS files, the role of the brush cache
      /**/$ ("#pic_code"). attr (' src ', '/static/img/verify_code.png ' + '? temp= ' +  Math.random ()); /*  */<script type= "Text/javascript" src= "core.js?v=20140829" ></script>
      /* Time * *
      ? v=new Date (). GetTime ();

Meta

    1. Add code to the head area in HTML:
      <meta http-equiv= "Pragma" content= "No-cache"/><meta http-equiv= "Content-type" content= "No-cache, "/><meta http-equiv=" Expires "content=" Wed, Must-revalidate 1997 08:21:57 GMT "/>

Ajax

    1. Set the property Cache:false so that Ajax does not invoke the browse cache .
      Cache:false

    2. Use AJAX to request the latest server files, plus the request headers if-modified-since and Cache-control, as follows:
      Beforesend:function(xmlHttp) {    xmlhttp.setrequestheader ("if-modified-since", "0");    Xmlhttp.setrequestheader ("Cache-control", "No-cache");  }

Replace

    1. The principle of replace replaces the page specified by the Replace parameter with the current page
      <script language= "JavaScript" >              function Jump () {                  window.location.replace ("b.html" );              }          

JS Clear Browser Cache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.