开发者

Re-executing JavaScript files

开发者 https://www.devze.com 2022-12-10 19:34 出处:网络
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 fa

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 mem开发者_如何学运维ory 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消