Live data from Hacker News

Gov.uk drops jQuery from their front end

web.dev

111–120 of 458 posts

Re: Gov.uk drops jQuery from their front end

#111

Earlier quoted context omitted.

I really don't get this discourse, jQuery API is much more ergonomic, concise and clearer than the DOM api. Sure you can do it but that doesn't mean you should

Just replace that one liner with a 15 liner.

document.querySelector('html')

And for React: https://javascript.info/custom-elements

Re: Gov.uk drops jQuery from their front end

#112

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();

I think the more direct comparison is document.querySelector('#element').style.display = 'none' That has the same ergonomics as the jQuery selector, and is just a bit longer. I feel like with editors that autocomplete, it's not enough of a difference to warrant the extra dependency.

[deleted]

Re: Gov.uk drops jQuery from their front end

#113

Earlier quoted context omitted.

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.

They are missing on a lot of expert backed Jquery optimizations e.g. https://github.com/jquery/jquery/issues/3143

They'd be even better to just use the browsers CSS animation support...

gov.uk doesn't have many animations anyway.

Re: Gov.uk drops jQuery from their front end

#114

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();

I think the more direct comparison is document.querySelector('#element').style.display = 'none' That has the same ergonomics as the jQuery selector, and is just a bit longer. I feel like with editors that autocomplete, it's not enough of a difference to warrant the extra dependency.

I think the vanilla JS is better actually, because I actually know what it's doing.

I've never used JQuery before and would have assumed calling .hide() on an element would set the CSS attribute "visibility: hidden" rather than "display: none"

Re: Gov.uk drops jQuery from their front end

#115
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 really don't get this discourse, jQuery API is much more ergonomic, concise and clearer than the DOM api. Sure you can do it but that doesn't mean you should

Yes, the DOM API is painful to work with.

Re: Gov.uk drops jQuery from their front end

#116

Earlier quoted context omitted.

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 w…

Oh god, Backbone. I absolutely hated that framework. It didn't even seem to do anything, it seemed like I had to implement all of the logic myself. Except I had to do it their way, for some reason, and practically nothing made sense. (I haven't touched it in years, though, so my memory is probably distorting my experience) I like the idea of React, just not what it has turned into. The amount of tooling that it has c…

Re: React, have you looked at Vanilla custom elements:

https://javascript.info/custom-elements

I've been using them lately and I think they are the bees knees.

Re: Gov.uk drops jQuery from their front end

#117
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).

> jQuery was making up for browser API shortcomings While this is true, I can still code circles around frontend developers using vanilla JS. The decline of jQuery is mostly due to the rise of webapp frameworks like React and Vue. But if you are tasked with adding like, a button to a static webpage, jQuery is still the king.

one of the nice features of AngularJS when it came out was the inclusion of the jquery lite api for interacting with the dom.

Re: Gov.uk drops jQuery from their front end

#118
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).

> jQuery was making up for browser API shortcomings While this is true, I can still code circles around frontend developers using vanilla JS. The decline of jQuery is mostly due to the rise of webapp frameworks like React and Vue. But if you are tasked with adding like, a button to a static webpage, jQuery is still the king.

I never really knew jQuery besides the five things that I googled, so once I had to do more "dynamic" frontend things I just looked into Vanilla JS and it kind of works for me. Not sure if I had WTF-moments besides the normal "this seems to be how things work" stuff, so I think it's easy enough?!?

Only thing I always have to look up is how to make sure my script is executed once everything is done and not before and "ready()" is obviously easier than adding an event listener to "DOMContentLoaded". Yeah, had to look it up for the comment.

Re: Gov.uk drops jQuery from their front end

#119
post #93
post #71

Earlier quoted context omitted.

There is .forEach() on NodeLists, so you can do stuff like this in every browser, no lib, no helper functions needed: document.querySelectorAll('a').forEach(tag => { // operate on tag })

how's browser support for something like "a:has(img[src$='.gif'])" though?

You probably shouldn't be making that query, unless you're doing something specific like web scraping and don't have control over the content of the site.

Re: Gov.uk drops jQuery from their front end

#120
post #111

Earlier quoted context omitted.

Just replace that one liner with a 15 liner.

document.querySelector('html') And for React: https://javascript.info/custom-elements

Other functions are much more difficult to replace

    $('.sth').closest('ul')
To me jQuery is like Regex or Linq. I think it had a really good api.
Post reply on HN