Some markup has things like JavaScript files or images or styles that make
cool stuff happen. And so, as soon as the browser gets the web page that it
asked for, it has to ask for tons and tons more things:
And here is the really dumb part about all of this: the browser usually has
to wait until most or all of these things come back before it does anything
important.
There are two ways to wait for things to be ready before doing important work.
The first is what we’ve been doing—putting the most important stuff last in
the HTML document:
<body></body>
<script>
// This is where we have been coding - after the<body>tags
</script>
In this case, we have the <script> tag at the very bottom of the document,
meaning that browser will display the web-page stuff (text, images, style
information, etc.) before it runs our code. Hopefully everything else will be
ready by the time the browser runs that code.
The other way to deal with this situation is to use a browser trick known as
on-dom-ready. DOM stands for Document Object Model. When browsers think
about web pages, they use the DOM. Browsers also let web programmers use
report erratum • discuss
The Mighty, Mighty Browser • 211
Prepared exclusively for Michael Powell