The Problem with Solutions

If there’s anything that there’s a lot of these days, it’s Javascript.

Seriously, take a look around. It’s everywhere. We’re not talking about the dumb marquee scripts and other “toys” that constituted the Dark Age of Javascript, either– it’s been the Rennaissance of Javascript for a while now– with Web 2.0, smart people are putting spectacular things together with Javascript every day.

“Web 2.0” has largely been about Javascript and our growing acceptance (and respect) for this much-maligned language, and as more people seriously started looking into the language, major libraries emerged to make life easier. Libraries like Prototype provide a layer of abstraction to protect us from browser irregularities, give us ways to handle data structures more naturally, and include “remote” request toolkits (ie, Ajax.Request and friends) that have quickly become the Web 2.0 standard.

This movement towards the use of foundational libraries has created its own niche market, the small compact scripts touting their lack of a requirement for these libraries, since they’re “too big.”

The problem with these little frugal scripts is that if you are using Prototype (or whatever library you prefer), the following things are probably true:

  1. They’re longer than their Prototype-based equivalents would be– being less frugal in your case ($$ is obviously shorter than document.getElementById, and that’s just one function call, iterations are worse)

  2. They’re more brittle, since they rely on different, sometimes spotty, ways of watching for browser irregularities (meaning more redundant code, too)

  3. They provide wildly different APIs. Use of Prototype, etc, encourages the building of similar APIs (ie, MyLibrary.myFunction() vs someRandomFunction())

  4. Their authors completely ignore the fact that caching exists and, in many cases, is good enough for most cases

I’m not saying that authors need to provide “Prototype” and “Lite” version of scripts they provide (this is free code, after all)– but if you’re using Prototype and you are looking at a non-Prototype-based script, you need to be aware of these issues. If you’re uncomfortable with the tradeoffs, have the chops, and the license permits, why not modify the script to sit on top of Prototype, rather than beside it?