What is domContentLoaded?
- This event typically marks when both the DOM and CSSOM are ready.
- This means that the render tree can now be built.
Take a Brief:
- Script tag have access to any element which appears before them in the HTML.
- DOMContentLoaded / jQuery.ready occurs when all the HTML is ready to interact with, but often before its been rendered to the screen.
- The load event occurs when all the HTML is loaded, and any subresources like images are loaded.
- Use setTimeout to allow the page to be rendered before the code runs.
For more details: https://varvy.com/performance/domcontentloaded.html