<SCRIPT src = "common. js"> </SCRIPT>
V1.1 after modification:
<SCRIPT src = "common. js"> </SCRIPT>
<SCRIPT src = "foo. js"> </SCRIPT>
A new Foo. js file is added, and common. JS is modified. The new class is defined in common. JS, and common. JS is used in Foo. js.
In this case, if you have browsed HTML files of version 1.0 before, the browser automatically caches common. js
When he browses the new version, it uses Foo. js of V1.1 and common. js of V1.0, which will cause a script error.
Solution:
Because CSS and JS are loaded using the <SCRIPT src =...> method, it is difficult to use ASP's server to disable caching. It is also difficult to use ajax to disable caching by setting HTTP request headers.
It seems that the random number is a good method.
// Method 1:
Document. Write ( " <SCRIPT src = 'test. js? RND = " + Math. Random () + " '> </S " + " Latency> " )
//Method 2:
VaRJS=Document. createelement ("Script")
JS. SRC="Test. js"+Math. Random ()
Document. Body. appendchild (JS)
However, if a random number is used, the JS file will never be cached and must be loaded from the server again each time, even if no changes are made.
If you visit a foreign website frequently, you can see that they usually use this method to solve the problem:
<SCRIPT src = "test. js? Ver = 113 "> </SCRIPT>
Among them, 113 of Ver = 113 is the version number, which is generally generated using CVS or other tools.
in this way, static files are cached when the cache is applied. When the version is updated, the latest version is obtained and the cache is updated.
for images to effectively use and update the cache.