JavaScript file not reloading in browser when modified on server

六眼飞鱼酱① 提交于 2019-12-09 12:41:13

问题


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?


回答1:


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> 

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.




回答2:


In general, the quickest way to force update is to press CTRL+F5 in the browser.

Otherwise you need to empty the browser's cache.

If you are using Firefox I'd recommend the plugin Web Developer Toolbar, where you easily can just click "Misc -> Clear Private Data -> Cache".



来源:https://stackoverflow.com/questions/1339887/javascript-file-not-reloading-in-browser-when-modified-on-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!