Monday 5 May 2008

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.


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.

1 comment:

  1. [...] 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 [...]