Reputation: 467
Which of the following codes is faster to complete all processing? I thought that code H was faster, but when I tried it, code B was faster (I think ...). Depends on the environment?
code H
<script src='js' defer></script>
</head>
<body>
</body>
code B
<script src='js' defer></script>
</body>
Upvotes: 0
Views: 48
Reputation: 1151
That depends on how you define "faster". Faster to download? Execute?
By definition, scripts with defer
always execute when the DOM is ready, but before the DOMContentLoaded event, regardless of where you put them. They would still need to be downloaded and only executed when they're supposed to - so the difference is almost unnoticeable.
Upvotes: 1