Tuesday, December 12, 2006

Dean Edwards: The window.onload Problem - Solved!

Dean Edwards: The window.onload Problem - Solved!: "The window.onload event is used by programmers to kick-start their web applications. The problem is that the onload event fires after all page content has loaded (including images and other binary content). If your page includes lots of images then you may see a noticeable lag before the page becomes active. What we want is a way to determine when the DOM has fully loaded without waiting for all those pesky images to load.

Mozilla provides an (undocumented) event tailor-made for this: DOMContentLoaded.

IE supports a very handy
(but non-standard)attribute for the <script> tag: defer. The presence of this attribute will instruct IE to defer the loading of a script until after the DOM has loaded. This only works for external scripts however. Another important thing to note is that this attribute cannot be set using script.

No comments: