Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Load event comes before DOMContentLoaded

simple document 👇

<html lang="en">
  <body>
    <div>xxx</div>
  </body>
</html>

I find Load event comes before DOMContentLoaded and I'm confused.

I know Load event will be triggered when document and static resource has been loaded, DOMContentLoaded will be triggered when document has loaded. Is that means Load always comes after DOMContentLoaded?

enter image description here

like image 799
Mia Avatar asked Oct 19 '25 16:10

Mia


1 Answers

The DOMContentLoaded event triggers when the HTML document has been downloaded and the DOM tree has been parsed.

The load event triggers, if all resources have been downloaded (HTML document, images, stylesheets, etc.).

Usually, load event happens after DOMContentLoaded event, because parsing the DOM tree is much faster then downloading all the resources. But in your case, there is only the HTML resource. Thus load will be before splitseconds before DOMContentLoaded, as both load the HTML but DOMContentLoaded has to wait for parsing the tree in addition.

enter image description here

like image 163
Adam Avatar answered Oct 21 '25 05:10

Adam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!