Live data from Hacker News

Gov.uk drops jQuery from their front end

web.dev

31–40 of 458 posts

Re: Gov.uk drops jQuery from their front end

#31
post #6

Earlier quoted context omitted.

For basic interaction, you don't need anything but vanilla JS. Browsers have come a long way since the days where jQuery was almost necessary to deal with all of the minor differences/bugs in various browsers.

I'll admit I'm a bit out of practice with the state of vanilla JS, but it seems like you'll be re-inventing the wheel for simple stuff. Like a collapsible section that's lightly animated. I worry too about people not considering accessibility. A lot of my bugs day to day is not being able to tab into things like hover menus or being able to activate buttons because someone forgot to consider correct event callbacks.…

I worry too about people not considering accessibility.

This isn't a complaint you can level at the gov.uk team. They're obsessed with accessibility. Gov.uk is probably the best example of a well-designed, well-built, completely accessible website on the whole internet.

Re: Gov.uk drops jQuery from their front end

#32
post #13

Earlier quoted context omitted.

jQuery still offers a much nicer experience. The built-in dom apis are neither very elegant nor ergonomic. // jquery $(selector).on('click', fn) // vanilla js document.querySelectorAll(selector).forEach(el => el.addEventListener('click', fn) )

It takes 1min to write a wrapper around that, though. Having said that, for the sake of 25kb - if you use more than a handful of features you might as well just include it.

That's the problem.

It takes only 1 minute to write a wrapper, so you will write one, and I'll write one, and your dog will write one.

Re: Gov.uk drops jQuery from their front end

#33
post #18

The gains aren't massive — certainly not something any human using the site would notice (about 20ms faster to render pages for the average mobile phone user). Still good to remove unncessary dependencies, though.

Not on an individual scale, no, but when you consider the millions of visits and views they get per year it adds up from a global / zoomed out point of view.

I'm sure with some math you can make a calculation on how much bandwidth and energy was saved with this One Clever Trick.

Re: Gov.uk drops jQuery from their front end

#34
post #11
post #9

Earlier quoted context omitted.

It's a much nicer syntax and has a ton of useful helpers. Vanilla js for similar things just looks like someone has waved the ugly stick at it. There are sound arguments against jQuery but the "you can just use vanilla" is the least convincing.

Not having to load yet another JS library on your page if you don't really need it is a pretty good argument, I'd say.

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 components around it. Many of them have ditched jQuery or have provided an API that doesn't require it.

Re: Gov.uk drops jQuery from their front end

#35
post #5

I miss the days when jQuery reigned supreme, and all the tenderfoot magpie developers didn't yet have the twinkle of React in their eyes

I don't; it was an improvement when BackboneJS came out so I could reason about larger scale applications, and another improvement when AngularJS came out so I could build and write tests for logical, reusable components, and another when React (especially in 2022) was there and reduced these components to simple JS functions.

That said, I don't like how complicated modern day front-end development is, to the point where you need a university degree to even try and fathom some of React's inner workings (e.g. https://reactjs.org/blog/2019/11/06/building-great-user-expe...) etc.

Re: Gov.uk drops jQuery from their front end

#36

Eh. Everyone hates on jQuery, but for most informational sites that's really all you need for basic interaction. Speed really isn't bad, and it's so straightforward that it's hard to mis-use at this point. I seem to have way more issues with newer frameworks/SPA if I'm not using chrome with no extensions. Makes me nervous dealing with important stuff like banking or government sites.

>> Eh. Everyone hates on jQuery, but for most informational sites that's really all you need for basic interaction.

The point seems to be that you don't even need that any more, so just get rid of it. Not sure why people latch onto cruft so much and defend its continued use.

On the performance side they cite 10 percent improvement, which doesn't sound like much to a lot of people. But remember that performance gains/regressions get compounded. Maybe there are 8 things that each eat 10 percent - you either start improving somewhere or you just refuse to even try. If I could improve 10 percent while removing a dependency I'd be all over that.

Re: Gov.uk drops jQuery from their front end

#37
post #27

Tangential, but sometimes I see people say that jQuery is dead/failed. While it's not as popular anymore, I think that's actually the perfect evolution for it. jQuery was making up for browser API shortcomings, and now many of those shortcomings have been addressed and been incorporated into browser APIs (not everything, but quite a bit).

I agree. Also reminds me of CSS resets, the goal of modern-normalize is to make itself obsolete.

Re: Gov.uk drops jQuery from their front end

#38
Javascript has become so nice, now that browsers support modules.

I use a module "dqs.js" for all my query needs. It contains only these two lines:

    export const dqs  = document.querySelector.bind(document);
    export const dqsA = document.querySelectorAll.bind(document);
And use it like this:

    import { dqsA } from 'lib/dqs.js';

    for (const rabbit of dqsA('#rabbits .green')) {
        ... do something with all green rabbits ...
    }

Re: Gov.uk drops jQuery from their front end

#39
post #31

Earlier quoted context omitted.

I'll admit I'm a bit out of practice with the state of vanilla JS, but it seems like you'll be re-inventing the wheel for simple stuff. Like a collapsible section that's lightly animated. I worry too about people not considering accessibility. A lot of my bugs day to day is not being able to tab into things like hover menus or being able to activate buttons because someone forgot to consider correct event callbacks.…

I worry too about people not considering accessibility. This isn't a complaint you can level at the gov.uk team. They're obsessed with accessibility. Gov.uk is probably the best example of a well-designed, well-built, completely accessible website on the whole internet.

I meant more for anyone building a website.

Re: Gov.uk drops jQuery from their front end

#40
post #34
post #11

Earlier quoted context omitted.

Not having to load yet another JS library on your page if you don't really need it is a pretty good argument, I'd say.

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.

Post reply on HN