Updates and New Info, HTTPS Issue Resolved (sorta)
This is an update and some new information on my DomLoaded object literal, based on Dean's and Matthias' code for solving the "onload" problem: that is, can we fire off some events when the document object model has loaded into the browser, but before all binaries and other dependencies have loaded? The idea is, speed up the page.
Once again, we only have to even bother with this because browser support for the DOM Events and DOMContentLoaded is sub-par. Mozilla Firefox and Opera 9 both support it, but others... not so much.
There's also some more caveats and research being done on when this can and can't be used... appears it's not the perfect solution I thought it was. Bummer.
I have however added code to make it work in most situations, although it's a kludge. Read on.
So per many a request I've updated my DomLoaded object literal script to be able to execute multiple times based on multiple calls.
This is useful from the perspective of larger systems where there are many things which need to be set up when a page or series of pages load. Say for instance there were some menus for an entire site which needed to be enabled but then for a specific location in the site there was some drag n' drop action which needed to be initialized? Well, now the script will do it.
In the past using the script you had to queue up all your scripts into a single init() script, all called by the single statement:
Now, with the new version of the script, you can do this multiple times:
Nice. I can't take the credit, there's others out there that have done a lot with the onload code as well, and many others which added multiple calls.
New Info and HTTPS Issue Resolved (sorta)
Further testing finds that the technique doesn't work fully under HTTPS in Internet Explorer. Because the script relies on:
Sigh. Browser differences suck.
How does it work? I've added support in the IE version to detect the protocol and then fire off the appropriate portion:
So there we have it. Let me know if it blows up for you.
Links of Interest
Just some additional reading:
- My demo screen
- Location object / protocol attribute
- Defer attribute
- More on the defer attribute
- Matthias on using "https:///" to solve the problem, without of course, a second file
Update: Thank's to Matthias I've updated the script, again. This is way cleaner and no extra file is needed. Thanks Matthias.
Update 2: Fixed some issues with the way the script was implemented for IE, noted in some comments, either here or on one of the other posts about this script.
Possibly Related Articles
Commenting is closed for this article.