Using SCRIPT’s defer Attribute
One of the seldom used attributes within the HTML tag library is the defer attribute on SCRIPT elements. As you can probably tell by the name of the attribute, defer instructs the contents of the script tag to not execute until the page has loaded. Take a look!
Deferring Your Scripts
<script> //do stuff (runs first) </script> <script defer="defer"> //do stuff, but defer it (runs last) </script> <script> //do more stuff (runs second) </script>
The deferred SCRIPT element's code will execute once the rest of the page's resources have loaded. What does this mean? Be sure that your document doesn't rely on any of the code within the script during page load. In the example above, the middle block will execute once the page has loaded even though it appears before the last block.
Olivier Rochard has written an outstanding (and more detailed) post about using the defer attribute on the Mozilla Hacks blog. His post details browser support (and quality of browser support...or lack thereof), advanced examples, and tips for using the defer attribute.
What I find funny about this tag is that it seems as though most of the script I see should be using this attribute.