在服务器上修改时,JavaScript文件不会在浏览器中重新加载 [英] JavaScript file not reloading in browser when modified on server

查看:83
本文介绍了在服务器上修改时,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.

这篇关于在服务器上修改时,JavaScript文件不会在浏览器中重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆