1

What would be the loading order of these two JavaScripts?

<script src="a.js">
<script src="b.js" defer async>

What happens to b.js that has both defer and async?

1
  • 6
    "If you specify both, async takes precedence on modern browsers, while older browsers that support defer but not async will fallback to defer." Source: flaviocopes.com/javascript-async-defer Commented Jul 29, 2019 at 20:02

1 Answer 1

2

As specified here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script

Async is a Boolean attribute indicating that the browser should, if possible, load the script asynchronously.

While Defer is a Boolean attribute that indicates to a browser that the script is meant to be executed after the document has been parsed, but before firing DOMContentLoaded.

So in your case, b.js would load after a.js

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.