However, sometimes we actually do want to wait. While the custom ready() event is great for
executing code once the DOM is available, we can also use jQuery to execute code once the
entire Web page (including all assets) is completely loaded.
This can be done by attaching a load event handler to the window object. jQuery provides the
load() event method that can be used to invoke a function once the window is completely
loaded. Below, I provide an example of the load() event method in use.
Sample: sample4.html
Include all CSS files before including jQuery
As of jQuery 1.3, the library no longer guarantees that all CSS files are loaded before it fires the
custom ready() event. Because of this change in jQuery 1.3, you should always include all
CSS files before any jQuery code. This will ensure that the browser has parsed the CSS before
it moves on to the JavaScript included later in the HTML document. Of course, images that are
referenced via CSS may or may not be downloaded as the browser parses the JavaScript.
Using a hosted version of jQuery
When embedding jQuery into a Web page, most people choose to download the source code
and link to it from a personal domain/host. However, there are other options that involve
someone else hosting the jQuery code for you.
18