- Jan 2, 2006
- 10,455
- 35
- 91
I really want to iron out *exactly* what happens when a browser loads a page. Please correct anything that is wrong.
Say that it's just a normal .html page with script and CSS tags at the top, images in the middle, and script tags at the bottom.
- browser downloads the actual html file
- browser parses the html file starting from the top and going down to the bottom
It does this synchronously. If there is a <script> file on line 8 will it wait for that script to download and run through once before proceeding to line 9.
- as it goes down the html file the DOM is being built at the same time, line by line.
- say that after line 90 there are no more DOM elements. The DOM is then completely loaded and created at this point.
- say that line 90-100 are script tags. Those script tags are then loaded and parsed and run. So if there is any jQuery in those scripts that need to select a DOM element, they can, because the DOM has been 100% loaded. *If* those same script tags had been added at the top, those DOM elements would not have been created at the time the script runs, so things would break.
- I'm confused when rendering happens. Does rendering also happen line by line as the html is parsed, or only after the entire DOM is built?
Say that it's just a normal .html page with script and CSS tags at the top, images in the middle, and script tags at the bottom.
- browser downloads the actual html file
- browser parses the html file starting from the top and going down to the bottom
It does this synchronously. If there is a <script> file on line 8 will it wait for that script to download and run through once before proceeding to line 9.
- as it goes down the html file the DOM is being built at the same time, line by line.
- say that after line 90 there are no more DOM elements. The DOM is then completely loaded and created at this point.
- say that line 90-100 are script tags. Those script tags are then loaded and parsed and run. So if there is any jQuery in those scripts that need to select a DOM element, they can, because the DOM has been 100% loaded. *If* those same script tags had been added at the top, those DOM elements would not have been created at the time the script runs, so things would break.
- I'm confused when rendering happens. Does rendering also happen line by line as the html is parsed, or only after the entire DOM is built?