以编程方式检查Web资源是否已加载到网页

时间:2018-03-19 17:52:14

标签: javascript html bash frontend

如何检查网站是否正在加载,例如,jquery或从imgur下载图像?我可以在Firefox / Chrome中查看此流量,但我希望采用编程方式,最好是在bash中。

我知道我可以卷曲内容,但有时一些外部的东西会加载各种各样的东西,我想检查哪些内容/脚本/资源确实通过了。

Like this

1 个答案:

答案 0 :(得分:0)

对于您的示例中的jQuery等外部库,您可以检查是否存在仅在该库中找到的全局变量:

if (jQuery) {
    // this resource has been loaded
}

if (someLibraryVariable === 'undefined') {
    // if this is undefined, this resource using this variable is not loaded on the page
}

如果jQuery或者你的测试变量没有被加载到页面,这将引发错误。

您还可以阅读任何脚本标记的src。对于图像,您必须阅读src图像标记。

相关问题