Ways to view and delete browser caches ===== "open
Recently found in development projects sometimes always have to clear the browser cache frequently, otherwise it always shows the outdated information
Browser caching has pros and cons, some data needs to be cached to make the page open faster to improve site performance, but some cache content must be cleared, the cache may cause some error data to be displayed.
Describes some ways to clear the browser cache:
Method one: Using META tags
< meta http-equiv = "Pragma" CONTENT = "No-cache" > < meta http-equiv = "Cache-control" CONTENT = "No-cache, Must-revalidate" > < meta http-equiv = "Expires" CONTENT = "0" >
This approach is simple, but not supported by all browsers, such as Chrome, which enforces the use of cached browsers.
Method Two: jquery Ajax clears the browser cache
//use Ajax to request the latest server files, plus the request headers if-modified-since and Cache-contro$.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) {//Do something} async:false });//directly with Cache:false,$.ajax ({URL:' Www.haorooms.com ', DataType:' JSON ', data:{}, cache:false, ifmodified:true, Success:function(response) {//Do something} async:false });
Method Three: Add a random number (letter) or the current timestamp after the URL
URL? ran= " + math.random (); URL? timestamp=+ new Date (). GetTime ();
Method Four: Add a date stamp after JS
Although it looks like the URL plus random number, but the principle is different, this best all JS files in the form of public introduction files, can save some trouble
<script src= "/res/js/plugins/metismenu/jquery.metismenu.js?${.now?string (' Yyyy-mm-dd ')}" ></script>
Method Five: Back-end processing
Front-end development JavaScript method to clear browser cache