What is the difference between async and defer in JavaScript?
While we import the javascript file using script tag we use async or defer or just normal script tags what is the difference.
// Normal Include <script src="demo.js"></script> // Defer Include <script src="demo.js" defer></script> // Async Include <script src="demo.js" async></script>
Async allows execution of scripts asynchronously and defer allows execution only after the whole document has been parsed.
With async, the file gets downloaded asynchronously and then executed as soon as itβs downloaded.
With defer, the file gets downloaded asynchronously but executed only when the document parsing is completed.
Just note this will not affect if you write the inline script.