Joel always said to be careful when using 3rd party libraries. From my initial impressions, JQuery is great. What should I beware of when using it? What are it's limitations? What headaches will I run into later on as I use it more?
One thing I've run into with jQuery is that you end up chaining a lot of items together, and it tends to quickly get unreadable if you are not careful.
an example I can think of that illustrates this is on John David Anderson's blog:
There’s a guy who wrote a logging function so you can figure out whereYou(are).whenYoureCoding().inThe(middleOf).a(jQuery).trainWreck().
I can see the power of chaining things together, but my guess is you’ve probably gone too far if you’re needing to log things to the console mid-swing. There’s probably little to no chance you’re going to be able to read it a week from now, too.
I've used it extensively and I have to admit, I'm yet to run into any serious brick walls! I have come up against a couple of bugs which I had to find a quick fix for myself, and then do extra testing with the next jQuery release to ensure that the bug had been dealt with properly, but that's something which applies to any 3rd party library rather than just jQuery.
I think it's a fantastic library I must say, and whilst the advice concerning 3rd party libraries has merit, with the amount of Javascript usage having rocketed in this Web 2.0 world, and with so many little discrepancies between browsers, having a well-maintained library can really speed up development as it saves you the overhead of having to do all the legwork yourself.
I guess if I was to issue one warning, it would be to make sure you don't go overboard with it - whilst it really accelerates Javascript development by abstracting away loads of logic you don't need to worry about, there's always the risk you'll start writing an inefficient application because you don't realise exactly what demands you're placing on the browser. I would therefore advise you do plenty of profiling with the likes of Firebug to check what's going on under the hood.
You can always consider different frameworks if jQuery doesn't suit. Here's an example of mootools.
MooTools is a compact, modular, Object-Oriented JavaScript framework designed for the intermediate to advanced JavaScript developer. It allows you to write powerful, flexible, and cross-browser code with its elegant, well documented, and coherent API.
I'm a big fan of jQuery (as evidenced by my having written both a plug-in and a Dashboard widget for it).
One thing to be aware of is which browsers jQuery supports. The docs site appears to be having issues at the moment. That's another thing to be aware of... ;-)
jQuery is great - it can do whatever javascript can do, but quicker, and in less code. Its only limitations are the ones inherent in javascript as a client-side scripting language. Like any tool, it's possible to missuse, but unless your scripting needs are profoundly basic there's almost no reason NOT to use it.
I came across the following in my blog reading. It's not really limitations in jQuery but common mistakes made when using ASP.NET developers using jQuery:
http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/
I've found jQuery to be indispensable when writing just about any useful bit of javascript. That said, one site I was working on wanted to do animations. I suggested NOT using flash, but performing the relatively "simple" animations that jQuery packages so well with jQuery. We used fades and slides and the like. In the end, it was too much for the browsers to handle (specifically IE, but FF showed signs of stress), and we had to scale almost all of it back.
jQuery is tons of fun to code with, and experiment with. It has a fantastic developer community that fields questions very quickly. Just be careful not to get too carried away! :)
My question always is about jQuery, do you really need it? You can easily build a quick ajax class on your own if that is what you want from jQuery, but do you need everything else? I always prefer to learn from other programs/libraries and then build my own so it fits my purposes perfectly rather than use a bloated library that I have to try really hard to make it work. Plus, what do you really learn by just using someone elses code? If you have any issues that appear, it is much harder to fix them if you do not know the code
@ mjc
$("a tip")
.you()
.can()
.chain()
.stuff()
.like()
.this();
And/or define a variable, for which to use the jQuery functions on:
var $tip = $("a tip");
$tip.choo();
$tip.choo();
$tip.train();
@ BrilliantWinter
jQuery is not at all bloated. It's one of the smallest libraries out there.
All it's functions are extends of the jQuery object, which means you can detach whatever functionality you don't use, and make the footprint of the library even smaller than it's default size (15kb, Minified and Gzipped).
jQuery - and every other library for that matter - provides an API which is the same across all A-grade browsers. This abstraction leaves your code cleaner and less error-prone.
Finally, jQuery is used by major "players". Companies like Google, Dell, Digg and NBC use the library. This is not only a big seal-of-approval, but also an assurance that the developers of jQuery are very careful when revising the library, making sure nothing breaks and no bugs are introduced.
You learn something new every day ;) I had not really used jQuery before, so I was just assuming it was similar to the other javascript libraries out there. I have been thinking about it and am actually considering implementing it in my own website. Thanks for the info!
@BrilliantWater - Most people don't use jQuery to "learn", they use it because it's quicker and easier to use and causes less headaches than creating all the methods yourself. And the whole "bloated" argument is totally moot; jQuery is one of the smallest libraries out there and with more and more people getting broadband it's becoming less and less of an issue.
Plus, since jQuery is hosted by GoogleCode it's likely that it'll already be in the users cache since so many websites use it!
jQuery is awesome! I keep saying to myself that I need to learn another library but I really don't. jQuery has everything I need. I know it's not suited to all projects but it certainly has a place in most!
I've been using it for about 6 months now and except for some of the slower developers on my team not embracing it (probably because of the intimidating appearance of some of the longer chains) I haven't run into a single problem.