John Sequeira


Friday, September 21, 2007
jQuery -- Love it

I've been meaning to write about jQuery, a fantastic javascript library that Dossy turned me on to.

jQuery is a new-school javascript library that allows you to do fancy ajax-y special effects in a microscopic amount of code. What sets jQuery apart from other frameworks is it's heavy use of CSS and XPath selectors to determine which elements you want to work on (add events to, hide/show, apply styles etc). Since every project I work on nowadays has an XHTML or XML component, I've invested a lot of time getting good with both scheme's, and as such I had a pretty good running start getting productive with jQuery. jQuery has a perl feel to it, in that you can pack so much expressive power into either a CSS/XPath selector -- they're the regex's of the structured text world. Also perl-ly is that when you're done, you really do have just a handful of unobtrusive javascript code to maintain. Admittedly, not everyone likes tiny code but it suits my scripting-language-addled brain. The base API is concise, easy to keep in your head, and even better: so ridiculously small in KB (14?) the page tax is ~ nil.

If the concise API doesn't do what you want easily, or you're solving a more sophisticated UI problem that should have already been solved (tabs, dialogs, etc), then you'll appreciate that jQuery is even more perl-y (CPAN-y?) in that there is a thriving community of plug-ins you can cherry pick that solve common UI issues.

The recently released jquery UI project offers you a quality assured set of UI extensions that follow certain code guidelines, for those looking for the don't-make-me-cherry-pick, batteries-included approach offered by dojo/scriptaculous/yui.

There have been two occasions recently where I had to implement small tweaks to different web based enterprise application where it wasn't clear to me how to do it with using the vendor's supported API's, or if it was even possible. In both cases, I implemented the customizations by including the jQuery library in a global template, adding an onDOMReady event handler, and writing in some new DOM elements using jQuery in ~ 5 lines of code. Problem solved - fast. Greasemonkey-type short-cuts like this risk not being upgrade friendly, but when implementing something not supported by vendor API's you're usually off the seamless upgrade path anyway. In addition, doing it the vendor way at the Java/C#/php level would almost definitely result in more complex code, and much more of it, that would be harder to maintain/merge anyway. And finally, if the need arises, it's much much simpler to turn off a jQuery page hack by commenting out a single line unobtrusive event-handler-add than it is to undo a compiled or scripting language library modification. It's downgrade friendly.

I now reach for jQuery every chance I get. Take a look.
10:20:14 AM      comment []  trackback []

© Copyright 2007 John Sequeira.
September 2007
Sun Mon Tue Wed Thu Fri Sat
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
Jun   Oct

Click here to visit the Radio UserLand website.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.
Yahoo: johnseq2
MSN: [email protected]
AIM: amped02139
Skype: johnjulian