Live data from Hacker News

Gov.uk drops jQuery from their front end

web.dev

131–140 of 458 posts

Re: Gov.uk drops jQuery from their front end

#131
post #111

Earlier quoted context omitted.

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.

You can also do this with DOM APIs, no?

https://developer.mozilla.org/en-US/docs/Web/API/Element/clo...

Re: Gov.uk drops jQuery from their front end

#132
post #111

Earlier quoted context omitted.

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.

Is it harder or just a bit longer-winded? E.g. i'm thinking this is the same behaviour

    document.getElementsByClassName('sth')[0]?.closest('ul');

Re: Gov.uk drops jQuery from their front end

#133

Earlier quoted context omitted.

Thanks to cache partitioning, this is no longer true. See, it turns out that by carefully leveraging cached retrieval of third party resources, scripts on two different domains can figure out if they are running in the same web browser, effectively pulling off browser fingerprinting. To stop this, modern browsers don’t share third party resource caches cross domain. So using a well known CDN no longer confers any ben…

ahh wasn't aware, and good to know

Indeed. We cannot have nice things.

Re: Gov.uk drops jQuery from their front end

#134
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.

This is not the case anymore but I remember when Angular was including a version of jQuery, and having methods like "doSthAsInJquery" (paraphrasing) in Angular, and I could still hear everyday that Angular didn't have the overhead of including jQuery.

I wish we could have standardized in the Linq-like API of jQuery.

Re: Gov.uk drops jQuery from their front end

#135
post #89

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

I think it's a bit of both. jQuery served the purpose of making web development more sane back in the day by handling all browser quirks. Part of that was the nice syntax. I personally have tried to drop jQuery, but truthfully, its syntax is just much easier to use. Nowadays, I use Cash https://github.com/fabiospampinato/cash to give me the nice syntax without the bloat. It strikes the perfect balance for me.

> I personally have tried to drop jQuery, but truthfully, its syntax is just much easier to use.

It's not just the syntax, it's also the expression-heavy and chained API which makes it much more flexible. As well as the set-oriented approach, which can lead to performance issues if you're not careful but is generally extremely enjoyable.

The DOM is an extremely procedural, plodding API, you need to name everything because you always need to set attributes and call non-chainable side-effecting APIs, not to mention the fecking NodeList which has to be converted to an array to do basically anything useful (in part because Javascript never really embraced iterators, and instead uses arrays for everything still).

I guess you could mitigate that with an "API adapter", but...

Re: Gov.uk drops jQuery from their front end

#136

Earlier quoted context omitted.

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.

You can also do this with DOM APIs, no? https://developer.mozilla.org/en-US/docs/Web/API/Element/clo...

This did not exist the last time I looked. TIL. Thank you!

Re: Gov.uk drops jQuery from their front end

#137
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 the company, often helicoptered into projects at the last minute to help them squeeze out the last bit of performance. His secret was he had a mental library of assembly language tricks applicable to the hardware of his day. But every few years his tricks were less and less relevant as hardware changed and compilers advanced. One day the grey beard was helicoptered into my leads project and everyone expected him to get them some gains. However, this was new hardware and none of his old tricks worked.

I think of this story whenever I see jQuery popup on Hacker News. There is always a strong contingent of devs who swear by this library. But to me, they are like the old grey beard who didn't update his knowledge as the times changed. At one time jQuery allowed them to be the hero and "Get Things Done" faster than their competition. But times have changed.

Argue with me if you must but take stories like this one for what they are worth. The writing is on the wall for jQuery. I was writing websites before jQuery existed, during the reign of jQuery and still today. If some candidate mentioned proficiency with jQuery during an interview I would be polite but internally I would note that the person might be out of touch. Not a red flag, but a yellow flag that I would follow up on. Nothing worse than bringing on a guy who claims to be senior/experienced and it turn out his old tricks won't work because they are no longer appropriate.

Re: Gov.uk drops jQuery from their front end

#138

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

When you are dealing with less than 5 "interactive things", jQuery is awesome... beyond that it might be better to consider a front-end framework. Jr devs have the tendency then to discard jquery because "is old" not because it isn't working anymore.

Though for that little work, I'd rather have a small local library that implements what I need over standard DOM & JS parts instead of the full weight of jQuery.

Unless of course I need to support legacy browsers, then jQ is a no-brainer - that crap is solved there and I don't want to have to deal with it myself.

And while jQ is large compared to my little home-grown set of wrappers, it is small compared to all the other stuff many pages draw in these days, so perhaps size isn't a great metric to criticise it on!

Re: Gov.uk drops jQuery from their front end

#139

Earlier quoted context omitted.

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.

Is it harder or just a bit longer-winded? E.g. i'm thinking this is the same behaviour document.getElementsByClassName('sth')[0]?.closest('ul');

Thanks, this is now standard it seems. TIL

Re: Gov.uk drops jQuery from their front end

#140

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

but see now you are reliant on jQuery and need to figure out how to load that first.

with vanilla, it would be just typing a bunch of extra properties.

Post reply on HN