diff --git a/dom.html b/dom.html index 9c5d486..5e1c534 100644 --- a/dom.html +++ b/dom.html @@ -660,7 +660,7 @@

21. defer vs async

Question: What is defer and async keyword does in a script tag?

Answer: HTML parser will ignore defer and async keyword for inline script (script that does not have a src attribute).

normal: When you have a plain script tag (no defer or async keyword), parser will pause parsing, script would be downloaded and exectuted. After that parsing resume.

-

defer: defer keyword in the script tag will defer the execution of the script. Hence script will be executed when DOM is available. Important point is, defer is not supported by all major major browsers.

+

defer: defer keyword in the script tag will defer the execution of the script. Hence script will be executed when DOM is available. There is good browser support for it.

async: If possible, set the execution of the script, asynchronously. async keyword has no effect on inline script.

Image copied from JS script execution