CodePark/ questions / Loading scripts & resources
START PRACTICINGPRACTICE
Frontend question · Browser & web performance › Loading scripts & resources

Which statement about the execution order of these scripts is guaranteed?

<script async src="a.js"></script>
<script defer src="b.js"></script>
<script defer src="c.js"></script>
b.js runs before c.js, and both run after the HTML is parsed

Deferred scripts keep document order, and they run after the HTML parsing finishes. So b.js always runs before c.js.

"
a.js runs first because it appears first" is the tempting wrong answer. a.js is async, so it runs whenever it finishes downloading. That could be before, between or after the other two. So nothing is guaranteed about a.js. "All three run in document order" is wrong for the same reason. "c.js may run before b.js" is wrong, because deferred scripts never change order, even if one downloads faster.