Ask HN: Why is jQuery hated but frequently used?

27 points by brettermeier ↗ HN
When you read HN or other programmer focused sites, you will read continuisly about that jQuery is a big failure of the past and should not be used anymore.

But when I look at current statistics (https://trends.builtwith.com/javascript/jQuery) or Enterprise software like SAP's Fiori UI5 framework, there is very often jQuery implemented.

Why is that so? I mean, if all those people are right, who are complaining about jQuery, why those big players still use it? Is it really because of old habits and technical dept, or is it because it is good?

I must say, I really enjoy writing JS with jQuery, still today. It's short, understandable, simple... Maybe not the fastest, but I really don't know if that's really the case.

37 comments

[ 3.8 ms ] story [ 65.4 ms ] thread
I think a lot of it is technical debt — it really was the bees knees ten years ago!
Because unfortunately, tech people equate old with bad.

Meanwhile, old can also mean the bugs have been worked out, doesn't change too drastically, and it's relatively stable.

jQuery gets the job done and has a low barrier of entry.

Worry less about what people think about a tool, and use the best tool for the job (even if you get flack for it). You'll win in the long run. When they're having to refactor their codebase, you're skirting by the wayside with reduced maintenance time and costs.

jquery isn’t bad because it’s old. It’s not even bad, it’s just irrelevant. It solved very real problems which no longer exist anymore.
The tech mindset is generally focused on change moving forward. Over time, jQuery was seen as a blocker for a number of areas:

- Browsers and the web becoming less painful to work with out of the box. If we all keep using jQuery, will these issues it fixes ever be addressed?

- Dependencies that hang around for a long time tend to increase technical debt or fear of common dependency-related issues

- A huge part of membership in a community involves signaling. Some of that signalling means syncing with what isn't liked, and speaking against it.

So you can get some people who want to live in a better world, some who want to be less annoyed by clutter they don't need, and others who just want to belong...and they see jQuery as a cheap ticket, especially if they aren't using it.

Still, jQuery is like any tool, best used by those who have a plan for working around the troublesome aspects...

>> - Browsers and the web becoming less painful to work with out of the box. If we all keep using jQuery, will these issues it fixes ever be addressed?

That's true, but the beauty of jQuery code is still missing in current JavaScript. It would be nice in my opinion if JavaScript would copy something of that shortness and beauty, that jQuery brings with it.

It would be interesting how much jQuery is needed to maintain compatibility over different browsers today, in the past that was the main use case. But nowadays I would use it because the code is a beauty to read and to write. For that beauty you need to load 87,5 KB of additional data, but that's not very much.

Still I get the idea of not needing to use another library. But I never saw that a new version of jQuery broke any code, but that may be my mistake.

In the age of frameworks, not only do browsers support the stuff that jquery invented, but those things are hardly done anymore.

It’s been ages since I last had to look up an element by ID or toggle classes. That stuff just doesn’t exist in the new way of doing things.

More's the pity. Now we just constantly delete whole branches of elements from the DOM and recreate them with react.js instead, which is far less efficient. React.js would probably cause your computer to use measureably more electricity even.
I really don't think it's that big of a deal compared to other things. JS based animations and scroll effects were the real issue. Now that CSS supports these things with GPU acceleration. React DOM changes are usually pretty insignificant unless something has gone wrong and gets stuck in some kind of loop.
That's not true, actually. React will re-use DOM elements wherever possible, even replacing the contents or individual attributes, or changing the order. But manual DOM operations with jQuery tend to be much more coarse-grained simply because they're so tedious, so what you say is likely completely opposite of the truth.
As a web developer you seemingly trust user input... ABOUT others' preferences... nowadays? :DD Either you know what works for you and use that or jump on hype trains and going to fell to your death sooner or later.

jQuery does one thing very well: abstracting away the peculiarities and idiocies of Ecmascript plus the browser quirks and provides a much easier way to do everyday things. The JS/ES implementations today are much better, than back in the IE days, but jQuery still provides an easier way to do things. JS standards bodies should have gone to John Resig with a big briefcase, give him a blowjob and asked him to let use jQ as it is and make it a standard. NOOOO, they had to implement everything in a convoluted way.

Plus a lot of devs know it from the heyday of the web, so why dump it, because "Stackoverflow statistics" say it's not trendy anymore? Gimme a break.

Speed issues in a JS app written in JQ in 2022? Gimme another break.

Now, you have these modern JS framework abominations... and people believe these are the second coming of God. :DDD Literal idiots everywhere. Everyone copies some bigdick thought leader/bigname company and think they evolved, when they actually do the same, just in a much more complex way.

Well, somehow you have to employ more people and slow down big corporate growth...

In case anyone else was wondering, this was the 205th usage of such word in a comment on our glorious subsection of dang’s internet: https://hn.algolia.com/?dateRange=all&page=20&prefix=false&q...

I’m not mad about it. I’m just always surprised to see it. My maturity level hasn’t reached production yet. I’m sorry.

:DD You need to shake people up from their stupor for fs sake...
You dump jQuery today because it's an unnecessary addition to your software stack if you don't need to support older browsers. And because jQuery supports so many browsers (especially IE) it's also fairly large.

I prefer using jQuery over the DOM interface because it's well ahead of the browsers, and you completely avoid bugs where you might implement something that's supported in Chrome but will be supported in the next version of Firefox, but you're running Firefox Nightly locally so it appears to work for you. But jQuery's big mistake, IMO was insisting on retaining support for older browsers.

If jQuery had created a jQuery.next or something like that, which dropped support for non modern browsers and focused on ensuring a common interface to the latest browsers and monkey-patching missing features into browsers which don't have them yet, I think it would continue to be popular with a significant developer base.

A fair amount of hate for jQuery is due to how it's used (read: misused) and not the tool itself.

For example, dev adds jQuery to a project when 5 to 10 lines of vanilla JS would do.

I must admit that I use jQuery also for very few lines, when I set up a mockup or something and just want to add some quick interactions. It is so convenient to just write $(".thisClass").show(); for example.

But I get it, if that page would be loaded by thousands of people each day, you may not want to make them all to load an extra jQuery file for what you could have written instead as a Script tag in a HTML file.

JQuery wasn’t a big failure of the past, it was a hugely important library that helped make robust interactive sites in the browser landscape of the time. That landscape has changed so it has become less relevant, and coupled with modern webdevs having decided that it’s reasonable to just say “use chrome” just as they said “use IE” before it, means that such a library is no longer as necessary.

I’ve seen a few people over the last few years saying that whatever framework is currently popular should be built into the browser, and in its era people were saying the same thing about jquery - and vigorously arguing for it.

For the same reason why we still use PHP. Because it keeps it's promises. So it does want it says it is going to do reliability.
If you believe hackernews php is having a bit of a reawakening. I see articles from time to time about how much better it is these days.
A lot of what jQuery used to provide is now baked into browsers, so for the most part jQuery is redundant nowadays. You'd still see it show up probably because the cost of removing jQuery from older systems usually isn't worth the hassle.

I would question the notion that jQuery was considered a failure back in the day. jQuery was practically necessary if you didn't want to deal with cross-browser issues.

(comment deleted)
jQuery is still shipped with WordPress and Drupal, two of the most popular CMSes out there. So I'm sure that accounts for some of it.
I imagine its wide use is residual, due to how prevalent jQuery was in the past. It is hard to describe how much of a godsend it was back when client-side coding meant dealing with quirks of major browsers and their different versions. It became absolutely dominant in an era right before the explosion of JavaScript libraries that we're still dealing with. Calling it a "big failure of the past" is nonsensical - it solved a very real problem in a very elegant way, and it was a must have for any modern (then) developer. It's no longer nearly as relevant because the browsers by and large addressed the underlying problem, but it does not surprise me that it is still entrenched in many a codebase.
The CRT monitor was a big failure of the past. They should have just used oled panels smh.
There are a fair number of answers about it being old, and I think that it's really important to contemplate what age means for software: the most obvious answer is that you can now use newer standard APIs for a lot of what jQuery did (which, to be clear, is great!) but also that there's been a lot of time to build a ton of projects using jQuery and for those projects to follow the common trajectory of starting simple and growing more complex over time.

Programmers tend to love building new things more than maintaining code and we're _really_ prone to misattributing the causes of problems, especially when that would mean admitting that we're not as good at managing complexity as we hoped. When Facebook's marketing push really got rolling, it started a fad of people crapping on jQuery and talking about how amazing React was — and I saw almost none of them built something which was either faster or, within 6 months, much easier to work on. The only exception I remember was a time where the React rewrite was what gave them political cover to slow feature development enough that they could fix a known design flaw.

That's not to say that newer tools are bad but the teams who did see benefits were already relatively mature: they actually measured performance, had a stable testing approach, refactored regularly rather than letting technical debt pile up until is burst into flame, etc. They would have been successful with almost any tool, and tended not to trash-talk jQuery when they left it behind since part of experience is understanding how much your choices matter.

You can probably just ignore any claim that jQuery is a big failure from the past - it's a massive success from the past. The huge problems it was solving so well just aren't problems anymore. You can certainly still use it.
Imperative, DOM bound. Try writing a library of reusable components or a large-scale app in jq. Or dont.

UI should be declarative and cross-platform.

Many useful UI components were written using jQuery. I no longer write anything in jQuery but I still use it at times because of this.

Give it another 5-10 years and I might find myself saying the same about React.

It's probably due to legacy software. If your software that uses jQuery ain't broke, why risk breaking it by striping it out? Does doing so even provide much business benefit? Probably not I'd say.
JQuery is great for DOM interaction. If you are making a complex web app, you should be using a framework designed for that and DOM interaction not through the framework is going to cause problems and convoluted code with side effects.

If you are making a web-site and not a web-application, it's great.

A lot of pain comes from a project that evolved from a complexity where JQuery was a good choice to a complexity where it is not a good choice, and the work wasn't done to convert the existing stuff.

jQuery once was designed to overcome JavaScript API differences in browsers and provide cross browser DOM manipluation and event handling, while still being as user friendly as possible - and it worked very good. You did not have to care - just use jQuery and you were done with cross browser stuff.

But it came at a cost. jQuery basically is a function that is linked to '$':

  function jQuery() {
     // ...
  }
  
  $ = jQuery;
The problem with jQuery today is, that most of the time the cross browser stuff is no longer necessary and therefore slows down your app drastically (especially hooking in every event handler). Most jQuery 'advanced' features are not used very often. This basically means, that in simple apps you could nearly replace jQuery with:

  $ = document.querySelectorAll;
jQuery is also often very inconsistent. Take for example the function itself - you can use different types of arguments (jQuery(function(){}), jQuery('string'), jQuery([]), etc.). In a small app, this does not make a difference, but nowadays, with HUGE JavaScript applications, this can be a real problem.

Most users liked the easy API of jQuery and don't know about these facts, so jQuery often is still the way they go...

It was very useful in the past, but most of the problems it solved does not exist anymore.

I used it extensively because I never really like the imperative approach, it’s a bit too error prone

I don't mind it for things when really needed, if I just want a few of it's conveniences for a modern website, I will use one of the tiny replacements for it like "cash.js"... I am with a lot of the other, if they would make a "Real" slim version that cuts out all the really old browser support, I would be using it again...
It's hated because it's frequently used.