<script async src="a.js"></script>
<script defer src="a.js"></script>
问下这两个文件哪个先执行?
<script async src="a.js"></script>
<script defer src="a.js"></script>
问下这两个文件哪个先执行?
For classic scripts, if theasync
attribute is present, then the classic script will be fetched in parallel to parsing and evaluated as soon as it is available (potentially before parsing completes). If theasync
attribute is not present but thedefer
attribute is present, then the classic script will be fetched in parallel and evaluated when the page has finished parsing. If neither attribute is present, then the script is fetched and evaluated immediately, blocking parsing until these are both complete.For module scripts, if the
async
attribute is present, then the module script and all its dependencies will be fetched in parallel to parsing, and the module script will be evaluated as soon as it is available (potentially before parsing completes). Otherwise, the module script and its dependencies will be fetched in parallel to parsing and evaluated when the page has finished parsing. (Thedefer
attribute has no effect on module scripts.)This is all summarized in the following schematic diagram:
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答5.1k 阅读✓ 已解决
3 回答1.8k 阅读✓ 已解决
①先执行,②后执行。 用给你说明理由吗?
①async
html发现了script标签
②defer
html发现了script标签