The example in this article describes how to prevent js from being cached in html pages. Share it with everyone for your reference. The specific implementation method is as follows:
Many friends will encounter this situation: if our page loads js, the js cache file will be called the next time it is opened, but it is very inconvenient for us when debugging. This article will talk about how to solve it. Let’s take a look at this issue together below.
The method of not caching JS is actually quite simple. CSS can also be used in this way under certain conditions;
Let everyone understand a simple principle of not caching:
When browsing different URLs, the browser will automatically cache the currently visited address once; and on the second visit, the cached page will be called, thereby achieving the purpose of fast page loading (page loading optimization) ;
Therefore, we can set a different value for the back of the page, so that the page can be accessed differently to achieve the purpose of not caching!
Here is a simple example:
Note: Because Math.random() can only work under Javascript, it can only be called through Javascript
Finally add an ajax method to prevent caching
I hope this article will be helpful to everyone’s JavaScript programming design.