Since a single web page may contain lots of external resource: external javascript, external css, images, applets, flash, etc., usually my conventional wisdom tells me that the window.onload event is fired when all the linked resources are finished downloading(though the external resources are usually downloaded in multiple threads or processes by the browser's implementation). The usual case may work in most of the time. But...what if the loading sequence is not what I take it for granted, some javascript bug may creep in somewhere and sometime.
After doing some search, I found it is not the case what i usually think. From this page: http://articles.techrepublic.com.com/5100-10878_11-5214317.html, it seems images are not loaded when onload event is fired. But from here http://stackoverflow.com/questions/191157/window-onload-vs-body-onload, it seems to me the images are loaded when onload is fired. There is more more confusion for me from this link http://forums.mozillazine.org/viewtopic.php?f=25&t=413504&start=0&st=0&sk=t&sd=a.
So my first part of the question is: Are all resources REALLY loaded when window.onload is fired?
Another closely related part of the question is: What is the resources loading order before window.onload is fired? I know for internal resources such as internal javascript or css, the loading order is from top of the page to the bottom (unless in IE, use the deferred script as here says http://stackoverflow.com/questions/65434/getting-notified-when-the-page-dom-has-loaded-but-before-window-onload). But what about external javascript and css resources? For example, if I write my page like this:
<external stylesheet...>
<external javascript #1...>
<external javascript #2...>
<script>
.....
window.onload=....
</script>
Then assuming a function in "external javascript #2" calls a function in "external javascript #1", can i be sure it ALWAYS works? Also if window.onload calls a function in "external javascript #1" also works as expected?
You may say the resource loading sequence and when to fire window.onload event is dependent on the browser implementation, as said here http://stackoverflow.com/questions/282245/what-is-the-event-precedence-in-javascript. But i am still wondering if there is a spec or convention in the public. So would you please refer me to a resource or tell me the facts to clear my confusion?