jQuery, a serious Prototype contender?

written by Tobie on August 23rd, 2006 @ 01:20 PM

Yehuda Katz recently wrote a post over at the jQuery blog about Why jQuery’s Philosophy is Better (than Prototype’s). After reading it, I spent quite a while on jQuery’s website, checked out the source code, the various adds-on and the great effects library.

Overall, I was deeply impressed by jQuery, which has matured at an amazing pace over the past months despite it’s relatively small exposure compared to Prototype. I haven’t started testing or using jQuery yet, but what I have seen has gotten me pretty excited, hence this post. Will I eventually ditch my favorite framework to join the growing jQuery crowd, difficult to say yet. However, what could make the balance tip in my case is neither the beautiful syntax nor the 10kb file size but the following, in order:

  1. a responsive and present maintainer,
  2. good docs and
  3. a tight community.

I know that these might seem surprising reasons to choose one framework over another, but the absence of the former has weighed considerably in disfavor of Prototype over the last months. Prototype’s latest stable release (v 1.4) is months old, and despite Sam’s unique post on the matter and some (unkept) promises, I’m still left wondering where Prototype is heading to. Note that my intent here is not to bash on Sam or to start a flame war: I highly regard and respect his work, the library he has released is superb and a pleasure to use.

jQuery still has some downsides however:

  • The source code is abominable to read because a small file size has been favored over adequate variable names.
  • Accessing an element’s original properties or methods through $() is impossible due the way jQuery’s $() wraps the DOM element.
  • There seems to be some speed issues with jQuery’s $() function (it’s actually a mix between Prototype’s $() and $$() functions which partially explains why).
  • The handling of events seems less robust than Prototype’s, especially in regards to memory leakage issues in IE.
  • There are still some cross-browser compatibility issues.

So is jQuery a serious Prototype contender? Definitely. Will I switch to jQuery? It depends mainly on whether:

  • jQuery’s upcoming release (v 1.0) smoothes out the above issues, or
  • Prototype gets its act together, maybe – and this is just my two cents – by opening up committing rights to a group of core contributors.

Update: both Yehuda and John Resig – founder and lead developer of jQuery – thoroughly commented on the issues I pointed out above, all of which should be cleared with the upcoming 1.0 release! Thanks guys for dropping by!

Comments

  • Yehuda Katz
    Yehuda Katz says:

    Hey,

    Thanks for the write-up.

    You’re probably right about the difficulties in reading the source-code. That said, jQuery’s excellent docs (including a very-soon update to my visual jQuery documentation [http://www.visualjquery.com]) make actually reading the source code less necessary than you’d think.

    John Resig, jQuery’s lead developer, has put a ton of work into an inline documentation system that supports the specific needs of jQuery, so the raw source code is chock full of documentation and examples.

    At least two documentation sources (John’s official docs and my visual docs) will make use of the parser he wrote that converts the inline docs into usable XML.

    As far as I know, John is working extremely hard at smoothing out the bugs in jQuery that you mentioned above. $ is, in fact, slower, but that’s because of the unique way that jQuery handles results from $ (specifically, it treats $, also known as the jQuery object, as the underpinning of the entire framework).

    Finally, feel free to submit bugs to http://proj.jquery.com/dev/bugs/ — John is quite good about fixing and closing bugs reporting in the jQuery trac (another great thing about the framework).

    Again, thanks for the write-up!

    Wed, August 23 at 13:45 PM

  • John Resig
    John Resig says:

    Hey Tobie – Glad to see that you’re considering jQuery. I’d just like to help clear up some of the points that you made:

    The source code is abominable to read because a small file size has been favored over adequate variable names.

    The jQuery 1.0 release (which is coming out this Friday) has been improved drastically. It’s a completely different piece of code than what it use to be. This is one version of the upcoming code, so that you can get a feel for how things are written: http://jquery.com/src/jquery-svn.js

    Accessing an element’s original properties or methods through $() is impossible due the way jQuery’s $() wraps the DOM element.

    Not completely so – for example, pre-1.0 you could do: $(“div”).get(0) to find the first div and get its raw DOM element object. In 1.0 you can now do: $(“div”)[0] jQuery returns a (highly modified) array that you can do whatever you want with – it’s very useful in that respect. Fundamentally, however, this is different from Prototype – as it will always return an array, even if you’re only retrieving one element (e.g. #foo).

    There seems to be some speed issues with jQuery’s $() function (it’s actually a mix between Prototype’s $() and $$() functions which partially explains why).

    Accessing an element by selector will, fundamentally, be slower than accessing an element by ID – however – the benefits of writing clearer code instead of a div/id soup is phenomenal.

    The handling of events seems less robust than Prototype’s, especially in regards to memory leakage issues in IE.

    Memory leaks, in jQuery, are relatively non-existent. This has been a major point of ours. The event code used is a derivative of the addEvent code written by Dean Edwards – which is completely leak free.

    There are still some cross-browser compatibility issues.

    There were a couple that existed, but these have completely been resolved as of 1.0. However, if you know of any compatibility issues that I may not have thought of, please let me know.

    Let me know if you have any more questions!

    Wed, August 23 at 17:09 PM

  • Heh… I’ve actually started using jQuery instead of Prototype and Scriptaculous. It has been a blast thus far and I haven’t really missed prototype at all. One thing I’ve noticed is the animation/effects are sooo much smoother because there is less going on and they are automatically queued up! The automatic queue has saved me lots of code.

    I’m actually going through on a big project and converting everything from prototype/scriptaculous to jQuery and a few plugins. Thus far I’ve seen a great increase in my own productivity and of the sites performance.

    Also, I wrote a patch for something yesterday and it got added already. Makes me want to write more patches.

    I don’t think you will have any regrets in using jQuery over prototype, at least I haven’t.

    Another library of interest to you might be mootools.net. They have some very nice approaches and a nice modification to Dean’s Base that I think would be a nice companion to jQuery to help out with some of the non-DOM JavaScript stuff.

    Sun, September 17 at 13:03 PM

Comments are closed