No. window.onload() is invoked when all resources (the document, objects, images, css, etc) have finished rendering.
Misread the question. Yes, it is entirely possible that the window.onload event will fire before a dynamically appended script has finished downloading. Scripts added using the DOM (document.createElement()) download asynchronously and aren't subject to the usual rule that window.onload() waits for all resources to finish downloading first.
I set up a test suite for you, http://jsfiddle.net/ywSMW/. This script adds the jQuery script to the DOM dynamically and writes the value of $ to the console during the onload handler. It then writes the value again a second later. Even with the script being cached, the first write to the console returns undefined, meaning the onload even has fired before the jQuery script has been downloaded and parsed.
Tested in IE and Chrome.
Re: the comments, if you want to check if the
onload event has already fired, you can set the value of a global variable inside the
onload handler:
var windowHasLoaded = false;
window.onload = function () {
windowHasLoaded = true;
}
function doSomethingWhenWindowHasLoaded() {
if (!windowHasLoaded) {
// onload event hasn't fired yet, wait 100ms and check again
window.setTimeout(doSomethingWhenWindowHasLoaded, 100);
} else {
// onload event has already fired, so we can continue
}
}