Script tags in HTML files will download, parse, and execute as soon they are encountered by the browser.
- BLOCKING: blocks the browser parsing while they downloads and execute
- EXECUTES: executes immediately after downloading (very bad for performance)
- WHEN TO USE: when the script is critical (in situations where the JS is essential for the functionality of the page)
- BLOCKING: does not block the browser parsing while it downloads
- EXECUTES: executes once HTML parsing is complete
- ORDER: always executes in the order in which the HTML parser discovers them
- WHEN TO USE: when the script is non-critical and when order matters
- BLOCKING: does not block the browser parsing while it downloads
- EXECUTES: executes as soon as they finish downloading
- ORDER: which means they can run in a different order
- WHEN TO USE: when the script is non-critical and when order does not matter
- NOTES: this could cause jank if the JS is big or complex because it could stop the functionality of your page as they execute (whereas defered scripts would execute after the page has loaded)
- JS execution will always block the HTML parser, as well as other JS execution