Live data from Hacker News

Gov.uk drops jQuery from their front end

web.dev

171–180 of 458 posts

Re: Gov.uk drops jQuery from their front end

#171

When I first started programming I was pretty lucky to get a job at a games company. My first lead was a veteran who had shipped a lot of AAA titles and he loved his war stories. He was personally interested in performance and he would often cite hardware timings for specific cpu instructions. One story he told a couple of times was about some grey beard who was before his time. The grey beard was once a legend in th…

As a counterpoint, I had a similar conversation with a report of mine about jQuery. He said it was not necessary and you could just use vanilla js. I said while yes that's true as a dev if I told you I needed you to implement a new payment provider for billing would you tightly and directly align with who we used or abstract it away via some wrapper so that if we ever had to change it wouldn't be difficult? Of course…

jQuery was a useful abstraction when browsers had inconsistent and clunky apis.

Modern browsers have apis that are about as convenient as jQuery's, are standard across browsers, consistent with the language, and guaranteed to outlive jQuery the library. Aside from dot-chaining in a monadic sort of way, jQuery offers no benefit to the developer, while costing about 30kB of javascript.

Re: Gov.uk drops jQuery from their front end

#172

I still use jQuery for frontend JavaScript when I can. It's so much more efficient than native JavaScript. I can't imagine anyone prefers to write document.getElementById('element').style.display = 'none' rather than $('#element').hide();

There are fewer and fewer people who know jquery, so while this might be convenient for you or me, this is just more cognitive overhead for programmers who don't know jquery. There are multiple ways to hide an element, and what does `hide()` do? Some future programmer will need to look this up, and every other jquery method they stumble across.

The main problem I have with jquery though is there's no convention for event binding, so there is literally no way to know if an element depends on a jquery event handler without grepping the js for every class, id, and data selector on the object. Even that doesn't always help. This makes it almost impossible to remove jquery from a project without breaking it.

Alpine or stimulus do a much better job of filling the event handling holes that still exist vanilla js. Dom traversal/manipulation in vanilla js is good enough, even if it isn't 100% as good as jquery.

Re: Gov.uk drops jQuery from their front end

#173
post #166
post #152

Earlier quoted context omitted.

what's so wrong about sprinkling some jquery on a static website (generated with hugo or jekyll)? On https://kubirds.com I use: jQuery appear: https://plugins.jquery.com/appear/ jQuery fancybox: https://fancyapps.com/docs/ui/fancybox/ Do not put jQuery to the trash yet, it still have a long life ahead.

I checked out kubirds, and even though I'm probably somewhat in your target demographic, I noticed that I couldn't discover what kubirds does without watching a video. Even scrolling down, and through the website, I didn't really understand it, until you compared to Nagios, which I am familiar with. Hope you don't mind a little unsolicited feedback. The website does look super clean! I would love to read a paragraph…

Thank you a lot for the feedback! We'll definitely do something about it :)

Re: Gov.uk drops jQuery from their front end

#174

The bashing of jQuery comes from junior devs. Of course a VDOM is clearer, more productive (and less performant) however most webapps with a minimum of logic have many legitimate uses of native dom/jquery in addition to the VDOM. And the interaction is perfectly safe as long as you do native DOM in the right lifecycle method (mounted). jQuery is a pleasure to use and give us a lot of power/expressivity. More generall…

The main value I found with jQuery was that the more your CSS selectors and jQuery selectors diverged, the more it felt like you were doing the same work twice.

Now I'm curious what the CSS looks like for devs who have only ever known VDOM frameworks. Regular CSS can be pretty bad, particularly on a mature project. Are we talking dumpster fire or three ring circus here?

Re: Gov.uk drops jQuery from their front end

#175
post #40
post #34

Earlier quoted context omitted.

To add: jQuery is a pretty huge library for what it does. Talking both bundle size and execution speed. Not that the latter is noticeable for most cases, but it's still a cost. The question is: What for? The primary use case for it has been cross browser compatibility plus a bit of sugar. The former is _gone_ and the latter is easily replaced with a few lines of JS. Then there is an ecosystem of libraries and compone…

30kb minified and gzipped! Less than most hero images. It's a nice API for simple stuff. I think if you strip out the AJAX support it can get extremely tiny.

It adds tens of milliseconds to just downloading on a fast connection, plus it has to be parsed before what ever you need it to do will be functional.

To compare, just roughly:

For roughly the same size you can get declarative/reactive rendering with React, or an optimized FP standard library with ClojureScript, or data driven visualizations with d3 (roughly 2x the size).

For a tenth of the size you can get stuff like htmx, or a json validation library (avj), or like someone said Preact (React alternative).

But for jQuery, you're paying that for basically nothing the browser APIs don't already provide. It was a godsend 10y ago, but with legacy browsers finally fading out, the last one being ie11, you really don't _need_ it anymore.

Re: Gov.uk drops jQuery from their front end

#176
post #19

Earlier quoted context omitted.

Except we've become so used to loading multiple megabytes of JS even on a simple blog post, that a 30KB library probably won't make a noticeable difference. Insofar as file size is concerned, I'd much rather pull in jQuery than some random npm package that depends on god-knows-how-many other random packages. Even GOV.UK, an incredibly lean website by today's standards, only noticed a 10% difference in their benchmark…

A 10% performance gain is quite a big deal, I wouldn't just shove it under the table like that.

Like every % comparison, it depends on the baseline.

Cue all the people going on about big O for parts of the code that are indistinguishable from noise in actual benchmarks.

Re: Gov.uk drops jQuery from their front end

#177

When I first started programming I was pretty lucky to get a job at a games company. My first lead was a veteran who had shipped a lot of AAA titles and he loved his war stories. He was personally interested in performance and he would often cite hardware timings for specific cpu instructions. One story he told a couple of times was about some grey beard who was before his time. The grey beard was once a legend in th…

I wish JS would get all the nice jQuery features, like all the css selectors jQuery has, like a nice feature would be when you retive an HtmlElementCollection to be able to apply some transformation to all elements without having to write a for, or make use Array.from and then use forEach. But I agree I would not use jQuery in new project and when possible I would replace jQuery in existing code too.

> to be able to apply some transformation to all elements without having to write a for, or make use Array.from and then use forEach.

This has worked for many years. I typically add a shorthand $ for the QSA part and on projects where I used to support IE11 you could add Array.from there but I haven’t bothered since IE was deprecated. jQuery does more but some of those things had performance impacts which were worth thinking about and the combo of QSA and fetch took care about about 90% of my projects.

document.querySelectorAll("div").forEach(i => i.innerText = "test")

Re: Gov.uk drops jQuery from their front end

#178
post #62

There's almost no point talking about javascript on HN with the amount of anti JS & anti framework rhetoric that happens here

jQuery isn't a framework though (that's half of why I like(d) it). Or are you talking about the number of lunatics on both sides of the argument crowding out everybody else?

Re: Gov.uk drops jQuery from their front end

#180

Earlier quoted context omitted.

As a counterpoint, I had a similar conversation with a report of mine about jQuery. He said it was not necessary and you could just use vanilla js. I said while yes that's true as a dev if I told you I needed you to implement a new payment provider for billing would you tightly and directly align with who we used or abstract it away via some wrapper so that if we ever had to change it wouldn't be difficult? Of course…

The problem is that most of the "abstractions" provided by jQuery are no longer abstractions and can frequently be replaced with simple alternatives that are directly provided by browser APIs that have extremely wide support. https://youmightnotneedjquery.com/ is a handy illustration of this.

I fail to see how replacing 1 line of jQuery with 10 lines of plain js is simple. Sure, you don't use those 10 lines all over the place, you write a function ... but then aren't you just recreating jQuery?
Post reply on HN