views:

225

answers:

8

I have started a new web application and have decided to use jquery as my primary javascript library... But still i want to get some pros and cons tips from SO users who used jquery ...

+6  A: 

All pros, no cons.

The only thing will be the execution time overhead that jQuery adds to load its files and execute its functions, but compared to the Pro of coding cross browser compatible JavaScript it is nothing.

Also compared to other JavaScript libraries jQuery is one of the fastest and smallest out there. Their community is huge and you can easily find support and good documentation.

Ivo Sabev
Anyone considering using a general purpose library such as jQuery should think carefully and be aware of the issues (such as the not insignificant one of including 70K of JavaScript on every page) before choosing to use it, so I think saying there are no downsides is unhelpful.
Tim Down
The production version is 24KB
Yassin
As Yassin said gzipped and minified jquery is 24 kb. Also I did mention that jquery comes with the slight inconvenience of some extra stuff to download and execute, but compared to the benefits it is insignificant.
Ivo Sabev
It's still 70KB to the JavaScript interpreter, and it's still 70KB down the wire if your web server doesn't support gzip.
Tim Down
You can reference it from - http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js they support gzip. 70KB in the interpreter is a joke in todays computer. Your concerns are paranoiac.
Ivo Sabev
Maybe not so much of a joke on a mobile phone, if indeed the mobile phone is one that jQuery supports. But this is a pretty pointless argument. File size is not the only downside to using a library like jQuery: there's an inevitable performance hit and a limited number of supported browsers, for example.
Tim Down
I would say with your own JavaScript the limited amount of supported browsers will be times higher. Check more about what browsers is jQuery supporting http://docs.jquery.com/Browser_Compatibility Your arguments are really weak. On a mobile phone with processors of couple of hundred MHz jQuery is still not a big performance hit, compared to what other JS libraries offer and will be slightly bigger than your own JavaScript (which might not be supported, because you might have missed some browser quirks). Cheers.
Ivo Sabev
For your first point, that depends entirely on the standard of one's own JavaScript, and I'm well aware of which browsers jQuery supports. As to the rest, it's all about context. For tasks that require a lot of DOM manipulation, jQuery can be an appropriate solution. For a page only requiring, say, simple form validation, I would say it is not at all appropriate. It's people blindly using jQuery for everything that I object to.
Tim Down
This is like telling me I can go walking 1000 feet instead of driving my car. Yes I can, but some people like to drive their car. It is pointless discussion form here on.
Ivo Sabev
OK, I agree this is pointless.
Tim Down
+3  A: 

You've made a good choice, don't worry. jQuery is a very well designed library - it is powerful, clean, well documented, and extremely popular. Learn it well, and it will be a powerful tool in your arsenal.

That said, I think that to be really aware of its pros and cons versus other frameworks, you should first learn it well. Only a deeper understanding of a tool enables you real comparison with other tools.

Eli Bendersky
+9  A: 

Pro's

  • Eliminates a lot of cross browser javascript issues
  • Can perform complicated Javascript operations in little code
  • Can easily add Ajax functionality to app
  • Has built in UI and effects libraries

Con's

  • Overhead of adding extra javascript to page
  • Learning curve may not be short for some developers
Craig
I would say jQuery learning curve is the shortest compared to all other JS libraries. One of the reasons for the jQuery popularity.
Ivo Sabev
+3  A: 

The only con I can think of is the occasional memory leaks. It is a great framework on top of javascript and is not restrictive.

That said, jQuery UI is terrible to my taste and if your application requires highly interactive UI try Ext JS.

HeavyWave
+5  A: 

Pros:

  • Large community
  • Useful for selecting and iterating over sets of DOM nodes
  • Eliminates some inconsistencies between browsers
  • Makes it easy for inexperienced JavaScript developers to do relatively complex scripting tasks

Cons:

  • Regular updates that change existing behaviour
  • Some confusing fundamental API methods (e.g. attr() method: what exactly does it do? It certainly blurs the line between attributes and properties)
  • Encourages "chaining", which leads to code that is difficult to debug: in a long chain of jQuery method calls, there's nowhere to put logging statements, so you need a full-on debugger
  • Short list of supported browsers
  • A general point about general purpose libraries: they encourage developers not to attempt to understand the underlying problems that the libraries try to solve, leading to a tendency to think of the library as being magical and to use it for absolutely everything
  • Adds 70K of JavaScript to every page where it's used when often a few bytes of non-jQuery code would do
  • Performance is generally much slower than the equivalent (well thought-through) non-jQuery code
  • Quality of plug-ins is very variable
Tim Down
I can see a great deal of bias here. It seems you've missed some pros... Btw, it's 19k with min+gzip. Chaining is not inherently a problem -- your experiences may say otherwise but you can't just make a flat statement like that and expect it to hold water.
J-P
Also, it's crazy to take one method ("attr") and then say that the whole API is "confused"... I feel that many of your points require substantiation.
J-P
J-P: As I'm sure you realise, I wasn't counting gzipping in the size of the library, since it is not always the case that it will be gzipped. Also, the non-gzipped size is more relevant when considering the work the JavaScript interpreter needs to do. Regarding your other points, I will flesh out my answer shortly. What pros do you think I'm missing? I'm open to the idea I've not thought of some.
Tim Down
I've added my own answer.
J-P
+2  A: 

The pros and cons are really relative to what your new web application will be doing. If it is going to be JavaScript/Ajax-rich and requires cross-browser support then jQuery is the way to go - no doubt. However, if you are only going to use JavaScript very sparingly, then it may be over-kill to include a large-ish framework, and it would be more efficient (in terms of performance and page size) to code the JavaScript directly.

Dan Diplo
There are other JS libraries. If its going to be very rich, then one which is focused on providing widgets (such as ExtJS) is likely to be better.
David Dorward
Why has this been down-voted? What in his answer is incorrect?
J-P
"rich" isn't just a synonym for "lots of widgets" (even though jQuery has plenty of such widgets, including jQuery UI). jQuery is a flexible programming framework, not just a set of pretty controls and themes (as useful as the latter may be).
Dan Diplo
A: 

Some other librairies are kind of... better... But JQuery is the easiest one to use, the one with the larger community...

xavierm02
+1  A: 

Pros: Lightweight, easy to use, good documentation, gets rid of nearly all cross-browser issues and normalizes the event model.

Cons: jQuery UI doesn't have much to offer, and the plugins are hit or miss.

If you're doing a very JavaScript-heavy Rich Internet Application, go with YUI or ExtJS. jQuery is an excellent DOM manipulation library, and is the best for highly custom UI work. But if you need lots of stock UI and a robust data management system behind it, you need a bigger framework to tie it all together.

jshalvi