This article describes the implementation method of making html pages not cache js. Share it for your reference. The specific implementation method is as follows:
Many friends will encounter this situation: if our page loads js, the next time we open it, it will also call this js cache file, but it is very inconvenient for us to debug. This article will talk about how to solve this problem, let’s take a look at it.
The method of not caching JS is actually quite simple, and CSS can also be used in this way under certain conditions;
Let everyone first understand a simple principle of not caching:
When browsing different URLs, the browser will automatically cache the currently accessed address once; and the cached page is called during the second visit, thereby achieving the purpose of fast page loading (page loading optimization);
Therefore, we can set a different value at the back of the page to keep the page accessed differently, so that we can achieve the purpose of not caching!
Here is a simple example:
Copy the code as follows:<script>
document.write("<script type='text/javascript' src='/js/test.js?"+Math.random();+"'></script>");
</script>
Other similarities, just add +Math.random() after the address
Note: Because Math.random() can only work in Javascript, it can only be called through Javascript.
Methods that add ajax to not allow cache
The code copy is as follows: xmlHttp.open("GET", "ajax.asp?now=" + new Date().getTime(), true);
Remember that the following now=" + new Date().getTime() is the key point and needs to be followed by parameters.
I hope this article will be helpful to everyone's JavaScript programming.