<script src="//some.cdn/jquery.js" async></script>
<script src="//some.cdn/underscore.js" async></script>
<script src="/my-app-which-uses-_-and-jquery.js" defer></script>
当defer
出现时,它指定在页完成解析时执行脚本。它不包括异步
脚本。
如果我有以下情况,所有脚本都将记录它执行的日期:
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js" async></script>
<script src="script2.js" async></script>
<script src="script3.js" defer></script>
</head>
<body>
<script>
console.log("Body script executed at : " + new Date());
</script>
</body>
我可能有这样的输出:
Body script executed at : Tue Feb 17 2015 00:05:08 GMT-0300
script2.js:2 Script 2 executed at :Tue Feb 17 2015 00:05:08 GMT-0300
script.js:2 Script 1 executed at:Tue Feb 17 2015 00:05:08 GMT-0300
script3.js:2 Script 3 executed at :Tue Feb 17 2015 00:05:08 GMT-0300