DEV Community

Discussion on: Async VS Defer - Understand The JavaScript Execution

Collapse
 
marzelin profile image
Marc Ziel

Modern browsers 'pre-parse' html to find all external resources and they start downloading them immediately (although with different priorities). So classic scripts don't block downloading other resources that are further in the HTML (only parsing is blocked).

There isn't much difference between deferred scripts and scripts placed before </body> tag - they're both evaluated just before DOMContentLoaded event but deferred scripts can be seen sooner (when they are placed in the <head>) and therefore start downloading a bit earlier.

Scripts with type=module (script modules) are deferred by default (but they can be async if needed).

Collapse
 
jeetsdev profile image
Ranjeet Singh • Edited

Hey, I wasn't aware of the 'pre-parse' technique of browsers. Yeah, there's not that much difference in placing script before </body> tag and differed script. We can still use our old school method without any guilt. Thanks for the clarification buddy.