Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When are module scripts (<script type="module">) fetched and evaluated?

When exactly are module scripts (<script type="module">) fetched and evaluated?

like image 251
Константин Ван Avatar asked Mar 13 '26 06:03

Константин Ван


1 Answers

According to the Living Standard for HTML (October 22, 2017.):

For module scripts,

if the async attribute is present,

then the module script and all its dependencies will be fetched in parallel to parsing, and the module script will be evaluated as soon as it is available (potentially before parsing completes).

Otherwise,

the module script and its dependencies will be fetched in parallel to parsing and evaluated when the page has finished parsing. (The defer attribute has no effect on module scripts.)

https://html.spec.whatwg.org/images/asyncdefer.svg

like image 184
Константин Ван Avatar answered Mar 14 '26 18:03

Константин Ван