重新执行 JavaScript 文件
我之前问过此类问题( 应用程序无法动态_re_load JavaScript 文件 )但我无法完全解决问题(如果有任何解决方案),所以我会以另一种方式,一种更简单的方式来解决这个问题:
可以从浏览器的内存中卸载文件以便稍后重新加载吗?
(显然,删除标签还不够。)
或者更相关的是,如果删除标签后重新插入标签,该代码是否会重新运行(显然不是)?
如何才能实现后者呢?
提前致谢。
I asked this sort of question before ( Application fails to dynamically _re_load JavaScript files ) but I couldn't quite resolve the problem (if it has any solution), so I will put this in another fashion, a simpler one:
Can one unload a file from the browser's memory for posterior reloading?
(Removing the tag is not enough apparently.)
Or more relevant, if a reinsert the tag after removing it, is that code rerun (apparently not)?
How can accomplish the latter?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以生成一个随机数,然后将其附加到文件名的末尾,如下所示:
.../script.js?r=0.25300762383267283
。然后浏览器会认为这是一个新文件,而不是从缓存中引用它。You could generate a random number and then attach it to the end of the filename like this:
.../script.js?r=0.25300762383267283
. Then the browser would think it's a new file and not reference it from the cache.我认为不可能卸载脚本文件。
至于重新运行问题,您可以尝试为调用 JS 文件的每个实例提供不同的 GET 参数(例如当前时间戳)。这可能/应该导致浏览器重新执行该文件。
你想达到什么目的?可能有比重新加载脚本文件更聪明的方法。
I don't think it is possible to unload a script file.
As to the re-run issue, you could try giving each instance you call a JS file a varying GET parameter (e.g. the current timestamp). That might / should cause the browser to re-execute the file.
What are you trying to achieve? There may be smarter ways than re-loading a script file.