0

我遇到了一种情况,我需要检查一个文件是否已经加载到 DOM 中,以便我不应该再次加载它。实际上,我有一个场景,其中有许多小型项目托管在同一个域上,但都有它们的资源,如 jquery、backbone.js 等(Wookie Widgets)。

问题是:我可以获得已经加载到 DOM 中的文件的名称列表吗?

PS:我需要获取加载到 DOM 中的 javascript 文件列表,并且我没有寻找任何解决方法。请让我知道任何方法来获取文件名的所有列表...加载到 DOM

4

2 回答 2

0

The standard way is to use a script loader. See some examples here: http://www.creativebloq.com/javascript/essential-javascript-top-five-script-loaders-8122862

This will give you full control on the scripts you want to load and their dependencies.

If you just want to use script tags, you could attach onload event handlers to each tag.

Or you could poll the page to check for the existence of the object the script is supposed to load (e.g. window.jQuery).

于 2013-09-24T04:52:49.973 回答
0

You can do something like this.

$('script').each(function(){
});

Here is a example in fiddle.

于 2013-09-24T04:52:52.680 回答