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. For example:

<script type=“text/javascript” defer=“defer”>
  alert(“After the page is ready”);
</script>
<script type=“text/javascript”>
  alert(“Before call of deferred script”);
</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.