-1

The code below loads YouTube API asynchronously

var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

How does it behave differently from simply having

<script src="https://www.youtube.com/iframe_api"></script>

on top of the page? What does it actually mean to "asynchronously load" something?

4

1 回答 1

2

当您异步加载 javascript 时,这意味着页面的其余部分可以加载而不会阻塞。使用该script src标签,页面加载的其余部分将被阻止,直到脚本完成下载并运行。

于 2013-10-21T00:23:32.703 回答