Live data from Hacker News

Gov.uk drops jQuery from their front end

web.dev

281–290 of 458 posts

Re: Gov.uk drops jQuery from their front end

#281
post #241

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…

Amusingly, I always joke that I'm fluent in jQuery, but no absolutely no javascript. As a mostly backend go/python/non-javascript developer that has always held true. It is just a tool in the belt for an engineer. Can you use jQuery in 2022 or later to solve really amazing problems that impact user experience? You sure can! Would you be better off to use a modern javascript variant and stuff like react instead? You a…

While I think that’s the right choice, I’d just like to point out that the problem with jQuery today is it was a library built to smooth over and fix differences between browser JavaScript engines (IE, well, IE).

Over the past 15 years or so browser JavaScript engines, except at the extreme edges, are roughly comparable. Further, a lot of the features of jQuery have been adopted into standard JavaScript.

So, the reason of eschewing jQuery, even for small pages, is simply that you don’t need it. Vanilla JS (or typescript) + modern CSS have pretty much all the same capabilities without any of the bloat. Using it today would be a little like using a library made to back port java 8 features onto a java 5 JVM.

Re: Gov.uk drops jQuery from their front end

#282

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

Yes, the DOM API is painful to work with.

Time to drag out this old classic: https://pics.me.me/what-does-l-use-jquery-jquery-mean-tmeans...

Re: Gov.uk drops jQuery from their front end

#283

Earlier quoted context omitted.

Update: fixed formatting A lot of times the jQuery syntax is easier to understand (IMO). Remove element exmample: jQuery API: $('.element').remove() DOM API: document.querySelector('.element').parentNode.removeChild(document.querySelector('.element')) or if you want to introduce another variable just to remove the element: const child = document.querySelector('.element'); child.parentNode.removeChild(child); Create e…

HTMLElement.prototype.remove exists everywhere except IE: https://developer.mozilla.org/en-US/docs/Web/API/Element/rem... Also for element creation: Object.assign(document.createElement("div"), { class: "foo", style: "display:none" }); I mean, you normally abstract these things with a helper fn or two, without importing the whole jQuery anyway.

IE 11 hits it’s EOL next month. So, really probably not a whole lot of reason not to just pull the trigger and inform everyone that complains of this fact.

Re: Gov.uk drops jQuery from their front end

#284
post #241

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…

Amusingly, I always joke that I'm fluent in jQuery, but no absolutely no javascript. As a mostly backend go/python/non-javascript developer that has always held true. It is just a tool in the belt for an engineer. Can you use jQuery in 2022 or later to solve really amazing problems that impact user experience? You sure can! Would you be better off to use a modern javascript variant and stuff like react instead? You a…

Why react though? Just modern JavaScript (and typescript) is a great replacement for jQuery.

The react part is just for when you need to build something that needs architecture.

Re: Gov.uk drops jQuery from their front end

#285
post #229
post #119

Earlier quoted context omitted.

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.

you could be using it already w/jquery though and if you just switched to the native selector it would stop working everywhere but safari. "#some_combo:has(option:selected[value=..]) + .." seems like a reasonable way to conditionally target something to me, is it terribly worse than some other way?

> is it terribly worse than some other way?

Yeah, it's fragile and will easily lead to bugs when someone changes the markup without realizing it's going to break some crazy selector in another part of the code.

It would make a lot more sense to just add a class to the element you're trying to select.

Re: Gov.uk drops jQuery from their front end

#286
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 })

I think it's just for brevity, rather than because a helper is needed . OP listed the entire source code of their module in their comment.

Brevity is cool, but that's kind of like naming all your variables one letter chars for brevity.

This is something every web dev will instantly know what it does:

    document.querySelectorAll('#rabbit .green').forEach(tag => {
      
    })
Whereas this is something nobody knows what the fuck it is because it's completely non-standard.

    for (const rabbit of dqsA('#rabbits .green')) {

    }
And get what, 10 characters less in one row? Basically nothing.

Re: Gov.uk drops jQuery from their front end

#287

Quoted post unavailable.

CSS is too much as well, client XSLT to XHTML is good enough for any reasonable website.

Agreed. So far it’s -4 karma for me.

There must be a grain of truth in there … somewhere. Nah, just an inconvenient truth.

Re: Gov.uk drops jQuery from their front end

#288

Earlier quoted context omitted.

That's not exactly the same, I don't think, because jQuery will give you all the `ul` that are closest to `.sth`, not just the first. You'd have to write a loop over the list returned from `document.getElementsByClassName('sth')` to get the same behaviour (because it doesn't look like the standardised `closest` works on lists.)

If i'm following right, i think this expression would match? Array.from(document.getElementsByClassName("sth")).map(e => e.closest("ul")) The jQuery is definitely nicer to read than this though

Yeah, that seems to do the same.

Re: Gov.uk drops jQuery from their front end

#289

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

These days it seems like you don't touch DOM yourself anymore because it's all about virtual DOM that is managed by the framework of choice, which is probably ReactJS.

Re: Gov.uk drops jQuery from their front end

#290

Earlier quoted context omitted.

> But to me, they are like the old grey beard who didn't update his knowledge as the times changed. Maybe it's just me but with all the rampant age discrimination nowadays in tech, I really don't like to see the continued propagation of this stereotype. All sorts of people of all ages are unwilling or unable to update their knowledge of new tech, there is no reason to link this characteristic to someones advanced age…

I sympathize with older devs, my dad is an older software dev. But you kind of do have to be old in order to have outdated knowledge: nobody young is going to learn assembly tricks which worked on MIPS and other past architectures. Older devs and companies not constantly learning new things and updating to best practices is a real phenomenon. On the other hand, anecdotally most older developers actually do keep up to…

> But you kind of do have to be old in order to have outdated knowledge

I'm not so sure. Google and StackOverflow are chock full of outdated (sometimes dangerous!) advice and knowledge on just about any tech subject, which hurts the young as much as the old.

I've seen just as many outdated suggestions from junior devs repeating the first thing they found on google as I have older devs with stale knowledge. I'd probably argue the former has been a larger problem, honestly.

Post reply on HN