tags:

views:

626

answers:

10

I have recently been thinking alot about where to draw the line, and I wanted to get some answers from you experienced developers out there. When is it acceptable to reference jQuery in a web app?

Some supporting arguments for Always Using jQuery:

  • You can reference jQuery from Google's repository, where it might already be cached on the client, eliminating the extra hefty request
  • You don't have to deal with common cross-browser issues, as they are already taken care of
  • You enjoy writing the code because it is developer-friendly

Some supporting arguments for Never Using jQuery:

  • Unsettling dependency of a third-party library, which could contain costly bugs, and could lead to unjustifiably poor performance
  • You have to learn a new syntax (just when you thought you had regular Javascript figured out...)
  • Even the simplest of tasks can perform poorly, because of the inherent complexity of the framework

I listed arguments as part of the question because I do not wish to have answers weighing the arguments of both sides. I am hoping for always/never answers, preferrably with test case scenarios (vague or detailed).

For example: "If I ever need to do any AJAX requests in my web app, I always use jQuery".

+2  A: 

It's acceptable when you want extra flexibility that just isn't in the DOM. By default I do not inclue JQUERY; however, as soon as I need to do any client side lifting I am moving to JQUERY.

I will even use JQUERY and MSAjax at the same time (Mostly on legacy pages which I am moving away from MSAjax).

JoshBerke
+23  A: 

If I ever need to do anything past document.getElementById() in my web app, I always use jQuery.

I honestly find most of your con arguments against jQuery pretty weak, particularly the last one:

Even the simplest of tasks can perform poorly, because of the inherent complexity of the framework.

Do not agree with that at all. jQuery is incredibly simple while powerful and that's what I love about it.

Paolo Bergantino
This is a good answer, thank you :)
Josh Stodola
First off - I love jQuery, too. But if your site does have a lot of Javascript functionality, the 19K is definitely overkill. jQuery does have perfomance issues: http://tiny.cc/DavidMarkJquery
Josh Stodola
LOL - I meant to say "if your site does NOT"
Josh Stodola
I have worked with newspaper websites and such where every kb counts, but in this day and age the 19k hit on the initial page load _FOR MOST CASES_ is pretty insignificant. As far as that link, while interesting, it just looks like a disgruntled guy nitpicking the source code of jQuery.
Paolo Bergantino
Besides, if you pull jQuery from the Google CDN, http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js, it's almost certainly in the browser's cache anyway, since it's so widely used.
George V. Reilly
+1  A: 

I would say that it's acceptable to use jQuery whenever you don't want to waste time dealing with different Javascript implementations. Which is probably quite close to always..

If what you do is a fairly small and trivial thing introducing jQuery (19KB minified) as a dependency might be a little overkill.

Don't reinvent the wheel if you don't have to!

Kimble
+2  A: 

It doesn't matter- you can write good code or rotten code, with or without jquery.

kennebec
+1  A: 

There aren't very many things I find javascript useful for that jQuery doesn't simplify.

For data validation, I prefer to have just one implementation of that, and since I have to make the server validate everything anyway, Might as well use AJAX for form validation. jQuery is very good at that.

For DOM Manipulation, jQuery provides a terse way of expressing what I'm likely to need. Certainly shorter and probably clearer than the 3 to 10 function calls I'd otherwise need.

Visual effects are seldom really required. They're hard to make portable too. For the benefit, if I cannot find a prepackaged visual effect, I'm probably better off without it. jQuery UI and several established plugins fit the bill.

There are plenty of other JavaScript Libraries, and I'm sure many of them are great, but unless they provide an absolutely indispensable function (eg, Google API), I can probably get jQuery to do it well too, and I'm already familiar with jQuery.

TokenMacGuy
+20  A: 

Unsettling dependency of a third-party library, which could contain costly bugs, and could lead to unjustifiably poor performance

Cumulatively, the jQuery developers have invested far more effort in eliminating bugs and performance problems on a wider variety of browsers than you or any other small team could afford to do.

Not-Invented-Here syndrome is a waste of your time.

George V. Reilly
Seriously. You already have the "unsettling dependencies" of network infrastructure, browser, operating system, etc. IE6 could suck the performance out of your app and you wouldn't have any choice but to live with it or try to work around it. With jquery you also have the option of patching.
bstpierre
+1  A: 

I never use jQuery... as for why? Never really thought about it, I guess I just haven't found a reason to use anything beyond plain Javascript. Plus, I don't like to rely on layers of abstraction I don't understand. (Of course, the things I do with Javascript aren't particularly complicated, so in my case perhaps jQuery really would be more trouble than it's worth.)

David Zaslavsky
+1  A: 

Today I added a Javascript patch to a page where I had to move a div out of its original place in the DOM tree and make it a child of the body, so that it could be positioned properly. I knew it would only have to happen once, on startup, to a specific id'd div, and that the page wasn't going to use any other JS behavior. So I wrote it by hand.

For anything more complex, it's jQuery. The high-level API just saves me so much time that I would otherwise have to spend "talking down" to the computer.

lawrence
A: 

Well, at least until EcmaScript 5 will come out and until the browsers will implement in their JavaScript Engines a common set of specifications, jQuery is the best tool that we have to solve problems cross browser. Not long ago every time you started a js file you had to start with a browser detect function. I used prototype, mootools, dojo and lately jQuery and I am very satisfied with the help they provide.

Elzo Valugi
A: 

Using jQuery just for browser compatibility is not a good enough reason for me to use jQuery. Most javascript framework these days already able to solve that. As for me, I would use jQuery if I ever need a very simple DOM manipulation tool that has Ajax support. If I ever need something beyond that, I would use other javascript framework. I would use Mootools if I need Javascript Object Oriented support and I would use Ext-JS if I ever need extensive built in widgets.

jpartogi