Hacker News new | ask | show | jobs
by PaulRobinson 867 days ago
I was around for the first Angular deprecation treadmill, and it was jarring.

I was thinking about doing some stuff for a hobby project recently and as a mostly back-end engineer, I am very out of date for most front-end code. I did a scout around, and didn't feel too impressed.

Finally last week I was thinking "I wonder what happened to jQuery", and there it was. Just as it ever was. Updated, freshened up, but completely recognisable and completely usable.

Is it new and shiny and full of awesome features? No. Do I understand it? Yes. Are there plugins for most things I need? Sure.

I feel old, but I'd rather make progress with something unfashionable than have to deal with deprecation and learning curves with something fashionable.

3 comments

I'm genuinely curious - what features does jQuery have that make it better than modern vanilla JS? Back in the day the vanilla DOM APIs were bad, so jQuery was great, but I haven't felt the need to reach for it in ages.
Better and shorter syntax, plugins, ecosystem.

Hide Show

```

$(".box").hide();

$(".box").show();

vs

document.querySelector(".box").style.display = "none";

document.querySelector(".box").style.display = "block";

``` Both work. The first is more clear

```

const $ = document.querySelector.bind(document);

$('.box').hidden = true;

$('.box').hidden = false;

```

1. Not really.

jQuery is designed not to fail. So if there's no `.box` on the page, jQuery will not do anything.

`querySelector` may return null, so `$('.box').hidden` will hard break your page if you're not careful enough

2. `$('.box').hide()` is just one such example.

The hilarious https://youmightnotneedjquery.com/ shows that jQuery remains more consistent, concise, and composable than most things in modern browser APIs

jumping in on this bandwagon... I sometimes look https://youmightnotneedjquery.com when I forget how to do something with jQuery.

Also, do you know if there is a jQuery-like that actually throws exceptions? Having `$('.box').hide()` tell me there is no `.box` would be pretty useful.

I would look around more. You might like one of the small reactive frameworks if you find the large ecosystem of React and Vue off-putting. My last jQuery app was several years ago, when I realized I was just maintaining a slower reimplementation of a reactive framework. These are mature technologies now that quickly save time and prevent headaches down the road. jQuery's best lessons have been absorbed into both the reactive frameworks and native JS and you can alias the handful of selectors you're used to.

For development, browsers and version managers/containers are stable enough that you won't be on a deprecation treadmill. Any pressure would come from including other people on the project, which you'd get even more of with jQuery.

I appreciate the 'do what works' mindset quite a bit but I hope you'll give a modern reactive framework or library a try; I'm glad I made the change.

What would you recommend?
Vue with Vite (the builder/runner) is a stable, open source option. It is really a lightweight start where you're mostly writing HTML with interpolated data, and Vue is updating values correctly and performantly. Just build your reactive HTML app in one file and break into separate components as you're feeling the spirit. https://vuejs.org/guide/quick-start

Mithril if you just want to drop in want a tiny, complete reactive library that doesn't require a build step--this one is most like what you might end up creating in a large jQuery app. You can understand everything from the homepage. https://mithril.js.org/

HTMX if you really like HTML conventions. This doesn't feel jQuery-like and depends on your approach to your server app. https://htmx.org/

If you were to pick just one, I think Vue would be the most rewarding.

jQuery still works great
It certainly does but only for very flat designs. I was in jQuery camp for a solid 15 years (2000~2015) but once you get a taste of reactive design, it physically hurts to go back to jQuery. For me, that is.