What are some empirical technical reasons not to use jQuery?

I am astounded by the number of front end developers that hack at HTML, Javascript and CSS all day long and that ignore tools like jQuery ( or other equivalent helper frameworks ) and refuse to use them. I am not talking about JavaScript gurus, I am talking about in the trenches every day Joe production developers. I get a lot of arguments that are more like excuses or personal opinions that I don't think have any technical merit, I want to make sure I am not missing something.

Question: What are some empirical technical reasons not to use jQuery?

I am not looking for religious or dogmatic arguments or subjective opinions "like some other framework is better", consider jQuery the straw man for all comparable frameworks in the question.

22572 次浏览
  • They can't justify the filesize (even though it is probably less than script which doesn't utilise the abstractions provided).
  • They don't want to rely on third party tools.
  • Their business does not want to run any libraries (for whatever reasons).
  • Their business does not want to run any JavaScript code not written by their employees.

filesize - but really, beyond that, it's an absolute god-send for cross-platform javascript and browser differences. You would have to have some very good reasons not to want it in your toolkit (or be a fundamentalist developer idiot).

By all means, I like jQuery, but there are some reasons not to use jQuery:

  1. 下载大小/带宽:jQuery1.5现在超过200K未压缩,对于一些人来说,库的大小太大了,无法证明其优势。
  2. Performance: Writing native JS will always be faster than abstracting it behind a library.
  3. Added complexity: Many people will download the entire jQuery library when really they only need a few neat features from it.
  4. Application Dependencies: Introducing dependencies always has its hang ups. If there is a bug in jQuery, you can debug and edit the file, but upgrading later introduces problems. You could leave the bug, but now you are dependent on jQuery's time table for a fix, not your own.
  • Learning: To actually code everything, and learn more. (Rather than using pre-coded stuff)
  • Size: jQuery has TONS of features you might not need, why make the user download so much code if it's not going to be used?
  • Alternatives: at this point, there are dozens of more powerful, well structured web frameworks out there.
  • Flexibility: Although jQuery is really flexible, you might need something it doesn't provide.

jQuery expresses everything in a DOM-centric paradigm which can be misleading and doesn't require any need to express things in an application pattern.

Many developers wind up programming themselves into a corner with this DOM-centric pattern and eventually realize they haven't created anything extensible or reusable.

Rebecca Murphey has a great write-up of her own switch to Dojo from jQuery - the blog post is more about why not jQuery versus why Dojo.

I would prefer to use jquery for dom manipulation or traversing the dom , which is really easy with jquery . Moreover, attaching an event or event delegation are so easy using jquery or other framework otherwise you have to write custom event attachment for IE or non IE browsers etc.

But it has some performance penalty when you use $.each instead of vanilla JS for and array.push()... other issues like if you bind an event and remove that without unbind it will have memory leak....

My conclusion is only use any framework for complex dom manipulation and rest use vanilla JS

Update 2015:

In this answer from 2011 I'm talking about libraries like jQuery, YUI or Prototype. Today in 2015 that reasoning is still applicable to frameworks like Angular, React or Ember. In those 4 years the technology progressed tremendously and even though I see considerably less prejudice against React or Angular than I saw against jQuery or YUI, the same kind of thinking - though to a lesser extent - is still present today.

Update 2016:

I highly recommend an article published few days ago:

  • Why jQuery? by Michael S. Mikowski, author of the Single Page Web Applications book

That article is basically a very detailed answer to this very question. Had it been available when I was writing the answer below - I would have definitely quoted it.

Original answer:

I'll answer about jQuery but those are the same arguments that I've heard against using YUI, Prototype, Dojo, Ext and few others. Main arguments that I've heard:

  1. file size, which in fact is 84.6 KB in case of jQuery 3.2.1 - probably smaller than the logo on an average website and can be served from Google's CDN which is likely to be already in the cache of most of your visitors. As using jQuery always means smaller file size of your own JavaScript files, it can actually mean smaller download, even if not already in the browser cache.

  2. speed - writing pure JavaScript may be faster, but writing portable JavaScript seems to be impossible for most of the people. A website that is faster but doesn't work on every popular browser is useless in the real world. Besides jQuery uses some pretty heavy optimizations to actually be pretty damn fast and keeps getting even faster with every release, so it's actually not so easy to write faster code by hand for anything other than trivial examples.(*)

  3. "intellectual property" - a company is scared using someone else's code - while in fact jQuery is open source and free software that is used everywhere from your grandma's blog to Amazon, from Twitter to Bank of America, from Google to Microsoft - if they can use it then any company can use it.

  4. I can't remember hearing any other argument being used seriously.

(*) Here's a trivial example: getElementById('someid') vs. jQuery('#someid')

Is using getElementById faster? Yes. And of course everyone always checks the parentNode to catch when Blackberry 4.6 returns nodes that are no longer in the document, right? jQuery does. And everyone handles the case where IE and Opera return items by name instead of ID, right? jQuery does. If you don't do it then your code is not portable and you introduce subtle bugs that can be very difficult to find. And getElementById is the most trivial example that one could possibly find - don't even get me started on events and AJAX and the DOM...

Update:

There is actually a fourth result of asking why someone doesn't want to use jQuery. I forgot to put it on this list because it is not really an answer but rather the lack of any answer. The comment I got yesterday reminded me about it. This is hardly a "technical reason" to be added to the list but may be interesting nonetheless and may actually be the most common reaction.

What I personally suspect to be the main underlying reason to all of those reactions, though, is what I believe to be the biggest obstacle to progress in computer science: "I don't want to use it because I never did, therefore it must not be that important."

It was once the reaction to optimizing assemblers, compilers, structured programming, higher level languages, garbage collection, object oriented programming, closures or pretty much everything that we now take for granted — and today it's AJAX libraries. Maybe some day no one will remember that we once used to manually interact with the raw DOM API on the application level like now no one remembers that we once used to write programs using raw, unadorned, inscrutable hexadecimal numbers.

Why not use jQuery?

I can't think of a good excuse to use vanilla JavaScript over jQuery (aside from the intimidation factor of learning something new), but some people prefer other JavaScript frameworks (like the excellent MooTools) due to the philosophical differences between them.

Some people simply don't like jQuery's DSL-ish syntax, but they recognize the importance of using a robust JavaScript framework.

Personally, I love jQuery, but I know people who use other frameworks and are no less productive.

Because quite often it's just unnecessary. if all I want to do is validate some input, or hilight some field then it's just as easy to write simple javascript / dom code. And jQuery doesn't really help in such simple cases, so the question should be why use it?

Clearly there are many cases where it is very useful, but sometimes people seem to use it for no real reason too.

One reason not to use a framework - and this is an extreme edge case - is when writing embeddable code for another website, such as a banner. Arbitrarily inserting some complicated library or another will be polluting the namespace and potentially breaking someone else's site. Not that I wouldn't put it past some advertisers to try anyway, the pond-sucking scum, but I digress...

I disapprove of adding a framework when one is already present and equally capable. I see it all too often and it's my pet hate, I see it as unwarranted bloat. That is another question entirely.

Other than that I cannot think of a justified reason not to.