Why do we use jQuery?

It’s a common question these days: “why use jQuery”?

Reasons given to avoid it are:

  • Large size
  • Poor UI Library
  • No class support
  • No script loader
  • None of this, none of that
  • Moan moan moan

As far as file-size goes, I think the lack of modularity could be a real issue. If we were building a fast-as-lightning mobile app, I’d break it into parts. Or use something else. Ender, for example.

But for a reasonably-sized website, here’s what we really want:

  • Friendly, familiar API: CHECK
  • Well tested, especially across older browsers: CHECK
  • DOM lookup, traversal, manipulation: CHECK
  • AJAX helpers: CHECK
  • Custom events framework: CHECK
  • A few simple animation effects, including a queue: CHECK

Ok cool, so jQuery is actually giving us a lot of stuff, and we can just build on top of it where we need to. I DON’T find that jQuery is providing lots of things that we’re not using. Also, jQuery isn’t dictating how we work with our own code – it just provides a toolset for DOM manipulation. That gives us a lot of flexibility to find our own style.

On top of this, at Twitter we add:

  • ES5-shim – for JavaScript strict mode support
  • Loadrunner – for script loading / dependency management
  • Our custom component framework

Here’s a few things we WISH we had:

  • HTML5 polyfill – for additional input controls
  • All of DOJO’s UI components, especially (personally) the datagrid

jQuery’s plugins and UI components are the parts I avoid, but are also the parts we can build ourselves. I envy the DOJO UI, because as a user I find the controls to be useful and reliable, but i always find it very hard to work with them. Their API is awful. I’d love to see a full port to jQuery.

Ultimately, jQuery is actually a useful tool. Long may it continue to be so.

  • I think jquery needs to be replaced.  But since the DOM will never be fixed, its probably the best hack we’ve got.  And thats all it is, a slimy hack that works.

  • kennethkufluk

    You’re so right. That’s why I said:

    jQuery features:
    * slimy hacks
    * nothing else

  • Mike Sherov

    jQuery 1.8 will have custome module build support, so you could ditch the pieces you don’t need. Check out the latest commits on github.

  • molokoloco

    Chained and expressive, things done with jQuery can be shared with everyone.
    You can cut and past any part of code and integrate in yours…Plus jQuery is very stable, working since years with it and nothing broken…I’m loving it !!! Simply.

  • kennethkufluk

    I’ve heard about that. It’ll be cool.
    But, like I said, we mostly use it all.