在服务器上修改时,JavaScript文件不会在浏览器中重新加载
所以我有这个ASP.Net 2.0网站,它使用JS文件中包含的功能。当一个网页加载js文件加载正常。但是当我在服务器上更改该文件中的某些内容时,更改不会传播到用户的浏览器。它根据过时的文件继续工作。如何强制浏览器从服务器重新加载修改后的文件?
So I have this ASP.Net 2.0 website that uses functions contained within a JS file. When a webpage loads the js file loads fine. But when I change something in that file on the server the changes are not propagated to user's browser. It keeps working according to the out dated file. How can I force the browser to reload the modified file from the server?
一种相当常见的解决方案(也在这里使用)在SO我想)是在javascript文件的url中添加一个查询字符串,其中包含一个版本号。当您更改查询字符串时,浏览器会将其视为新文件并下载而不是从缓存中选择。
One rather common solution (that is also used here at SO I think) is to add a query string to the url of the javascript file, containing a version number. When you change the query string, the browser will treat it as a new file and download it rather than picking it from the cache.
<script type="text/javascript" src="http://example.com/file.js?v=2"></script>
在上面的例子中,更改 file.js?v = 2
到 file.js?v = 3
会强制浏览器下载文件,而不是加载缓存的 file.js? v = 2
。
In the above example, changing file.js?v=2
to file.js?v=3
would force the browser to download the file, instead of loading the cached file.js?v=2
.