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!
Unconditional Requests:
Conditional Requests:
The Document Object Model – is a model of information as it pertains to a browsers request/response. In many ways ECMA/Javascript was born as a direct relation accessing page elements and became the default DOM Library solution for many of the browser objects (document.frm etc). However, implementation and support is non-unified and sparse across all browsers.
Essentially, the DOM Being loaded is just a definition to say that the page is being rendered and the content has/is being invoked. This is something that cannot be counted on in regards to accessing DOM Object so, it is unfavorable method of interaction. Generally, you should use the ready status which means that the DOM is in a ready and waiting state of request.
Yep loads of difference – execution order of the client side code means where it will be loaded. Load with the entire page object or load after all content.
Yes and No. 🙂 No Real Guarantee but, with javascript/jquery used you can use the onload event of the body to identify all elements of the page successfully loaded. This is a trick question btw. No real answer to my knowledge unless, I am mistaken to what you asked…