Hello! I've been away from web design/development for a long, long now and have recently begun to get back into it. I started off doing things just to make them work, and now that I'm getting back into it, I would like to understand things a bit more clearly - including when the DOM is requested by the browser to when it is fully loaded, and the difference between script placement at the top and bottom of a page.
I realise that this is more a post for http://doctype.com, but I figured I would get a more technical answer from here. I would also like to have made this a community wiki, but I don't have enough points...as yet.
Please feel free to correct me here - My questions/assumptions:
- When the browser makes a request for the page, the server responds with a Document Object that contains the hierarchy/order of scripts, css and html - correct?
- Once received, the browser then builds a Document Object Tree - is this when the DOM is ready or when it starts rendering elements on the page in a browser?
- In that regard, what is the difference between "when the DOM is loaded" and "when the DOM is ready"?
- Is there any difference between placing (java)script at the top (in the head tag) or at the bottom (before
</body>
tag)? - Is there an DOM event that fires when all assets (css, images, javascripts, etc) are fully loaded by the browser? I ask this as sometimes I might have a background image still being loaded by the browser, and well before it can complete, my Javascript animations already start executing.
Thank you for taking the time to read this, and i look forward to your responses!