No Mod Required

JavaScript Dispatches From My Kilobyte Addled Brain.

I’m reading John Resig’s excellent Pro JavaScript Techniques. A great book for any JavaScript programmers in the audience.

Anyway, last night I was reading the chapter on image galleries. In it, Resig, comparing Lightbox to Thickbox, writes:

“Due to the amount of extra features that ThickBox includes, along with the reduced code base, it is certainly a desirable alternative to Lightbox”

The part about the reduced code base struck me as a bit odd as Thickbox requires JQuery to function. At the time of reading I thought JQuery was about 30k packed (it turns out it’s 26.5K packed,) so to my mind, Lightbox, which is a standalone script, being bigger than that seemed improbable. And that estimate didn’t even factor in the Thickbox code itself.

Stranger things have happened of course, so I spent a few minutes today looking into all the pieces to flesh out the story and now I think I see what Resig was referring to- if you’re already using JQuery, the Thickbox script file (11.3K unpacked/ 5.83K packed :) ) is smaller than the Lightbox script file (12.3K unpacked.)

It’s especially nice that Thickbox pushes a packed version at the user, by the way.

That said, my original “huh” was justified as, if one is starting from scratch or adding a feature to an existing site that doesn’t already use JQuery, then the total code cost for inserting Lightbox is considerably smaller than Thickbox (JQuery IS getting served to the browser after all.)

Of course, if you take a look at Lighbox 2, then Resig is even more right as the total cost of code on that one, written on top of Scriptaculous and Prototype, is 103K.

For what it’s worth, that’s nearly twice the weight of my whole home page.

What does all this mean? Nothing? Everything? Who cares? Something like that :)

Leave a Reply

Note: Wrap all of your code blocks in <code>...</code> and replace < and > with &lt; and &gt;, respectively.