onDOMLoad: Faster javascript for faster pages with a cross browser version of DOMContentLoaded

I have been quite entertained by all the recent talk about page loading speeds, optimization and profiling (eg: YSlow), so I decided to wrap up one of my functions into a usable form for you to dissect.

I call it, onDOMLoad.

Go and have a look at the demo of onDOMLoad.

onDOMLoad is a wrapper to the code suggested by Dean Edwards,Matthias Miller & John Resig. It is cross-browser capable and I hope pretty easy to understand.

Download

The Javascript is available to download here and here in minified form.

I have fully documented the uncompressed version

I like easily readable code, as I will often come back to it 6 months or a year later, and I hate spending hours working out how my own code runs.

Why use my version

onDOMLoad does vary from the few other solutions out there. It is very small, 1K minified. It works nicely in co-operation with the window.onload function. But most importantly, onDOMLoad allows multiple functions to be specified.

Future stuff

I have seen some great possible improvements, like Hedger Wangs implementation of Diego Perinis IE readyState check. I will post more updates here when I think they are ready.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Reddit
  • Slashdot
  • StumbleUpon

2 Responses to “onDOMLoad: Faster javascript for faster pages with a cross browser version of DOMContentLoaded”

  1. Tanketorsken… » onDOMLoad javscript funktion Says:

    [...] på, og synes det er lidt overkill at bruge jQuery bare for det Så har fundet en funktion her. Den er ikke testet, så ved ikke om den fungerer, men det finder jeg ud af i [...]

  2. James McCulloch Says:

    Thank you so much! You are a genius.

    Have been struggling for two days with my Onload events not working in IE8 due to it hanging while downloading objects. Was at my wits end! Your OnDomloaded function is brilliant as IE8 was downloading the objects fine, just not reporting that it had done, so the events never fired!

    I can sleep again! Many thanks for this brilliant piece of code!

Leave a Reply

Byting the hand that feeds you…