Live data from Hacker News

Gov.uk drops jQuery from their front end

web.dev

431–440 of 458 posts

Re: Gov.uk drops jQuery from their front end

#431
post #417

Earlier quoted context omitted.

That's not the point. The point is that this is a strawman. "Enough helper functions" to get to jQuery is 288580 bytes. A quarter of that, or even a tenth of that, is already a pathological case and way beyond almost every case of "jQuery substitution" that would happen in practice.

I could read and understand the entire jQuery source code in a single afternoon -- it's not that big. Even in the few minutes I spent reading it, I learned a few things I didn't know. The worst thing about the web as a platform is the need to count bytes.

Once again, my friend, that's not the point, and I'm not even talking about it anywhere. I get it that you like jQuery, but your reply defending it has absolutely nothing to do with my reply.

Nobody is reimplementing the 280k of jQuery as part of their projects, so no, you won't be "at jQuery anyway". That's bullshit.

Re: Gov.uk drops jQuery from their front end

#432
post #431

Earlier quoted context omitted.

I could read and understand the entire jQuery source code in a single afternoon -- it's not that big. Even in the few minutes I spent reading it, I learned a few things I didn't know. The worst thing about the web as a platform is the need to count bytes.

Once again, my friend, that's not the point, and I'm not even talking about it anywhere. I get it that you like jQuery, but your reply defending it has absolutely nothing to do with my reply. Nobody is reimplementing the 280k of jQuery as part of their projects, so no, you won't be "at jQuery anyway". That's bullshit.

I don't like jQuery -- I mean I use it but it doesn't occupy enough brain space to even have a strong opinion on it either way. If I took jQuery out then I'd have to care more because would need to re-implement all the pieces of jQuery that my projects already use. Is that going to be 280k worth? No. Is going to be a couple of one-liners? No, because jQuery hides a lot of complexity under it's relatively simple API that take a lot of JavaScript to reproduce.

It's not crazy that to accomplish what jQuery accomplishes without jQuery you're going to need almost the same amount of code as jQuery. It's not re-implementing the DOM -- it's a pretty thin but broad wrapper. If you don't need something, remove it.

https://github.com/jquery/jquery#how-to-build-your-own-jquer...

The whole point of using a library is to outsource the problem somewhere else.

Re: Gov.uk drops jQuery from their front end

#433
post #431

Earlier quoted context omitted.

Once again, my friend, that's not the point, and I'm not even talking about it anywhere. I get it that you like jQuery, but your reply defending it has absolutely nothing to do with my reply. Nobody is reimplementing the 280k of jQuery as part of their projects, so no, you won't be "at jQuery anyway". That's bullshit.

I don't like jQuery -- I mean I use it but it doesn't occupy enough brain space to even have a strong opinion on it either way. If I took jQuery out then I'd have to care more because would need to re-implement all the pieces of jQuery that my projects already use. Is that going to be 280k worth? No. Is going to be a couple of one-liners? No, because jQuery hides a lot of complexity under it's relatively simple API t…

Alright, we seem to be talking past each other. Maybe that's the sign this is not a productive discussion.

I'm not calling jQuery is bloated or difficult to read, nor I am telling anyone they should count bytes.

> Is going to be a couple of one-liners? No, because jQuery hides a lot of complexity under it's relatively simple API that take a lot of JavaScript to reproduce. > It's not crazy that to accomplish what jQuery accomplishes without jQuery you're going to need almost the same amount of code as jQuery

Once again, that's my whole point.

What I'm saying is that jQuery isn't a 100-line library. The whole of jQuery is not being trivially reimplemented at several places. Projects reimplementing portions of jQuery functionality (a la youmightnotneedjquery.com) are usually only reimplementing very very few things, and are leaving out lots of stuff. Different projects have different needs, some people don't need the whole library, some do, others don't care. That's it.

Re: Gov.uk drops jQuery from their front end

#434
post #32

Earlier quoted context omitted.

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.

Then compare it with dog's and pick the simpler one :) I don't know what's wrong with a utils.js file that only has what you need in a way that fits your project exactly. Woof.

your dog will not look for a simpler impl before making one.

your npm's dependencies authors cat will write a small wrapper and wont know about yours.

Re: Gov.uk drops jQuery from their front end

#435

Earlier quoted context omitted.

It is a bit weird to consume an iterator into an array when a NodeList is already iterable. Not sure why it caught on.

Usually it’s because you want to use an array function like .filter() that isn’t implemented by the iterable itself.

NodeList.prototype.filter = Array.prototype.filter;

and you can querySelectorAll('...').filter(el => ...) without any copies.

Re: Gov.uk drops jQuery from their front end

#436

Earlier quoted context omitted.

It is a bit weird to consume an iterator into an array when a NodeList is already iterable. Not sure why it caught on.

I'm also one of those guys that will always spread NodeLists (and other iterable-but-not-array type of objects) but it's really only because I find functional style a lot more readable than imperative style for loops. It might be iterable, but if it doesn't have map/filter/reduce and friends, might as well not be for me.

NodeList.prototype.filter = Array.prototype.filter;

and you can querySelectorAll('...').filter(el => ...) without any copies.

ditto for other mentioned functions. Prototypal nature of Javascript is there for a reason.

Re: Gov.uk drops jQuery from their front end

#437
post #189

Earlier quoted context omitted.

You can extend HtmlElementCollection prototype with any methods you like. (it's NodeList, btw, what's returned from querySelectorAll)

There is an issue you need to be aware , be careful if you hide the fact that this collection is "live". I mean this part from the docs >An HTMLCollection in the HTML DOM is live; it is automatically updated when the underlying document is changed. For this reason it is a good idea to make a copy (eg. using Array.from) to iterate over if adding, moving, or removing nodes. So you need something that will also be effic…

Same issue applies if you mutate array you're iterating over during iteration using those Array.prototype functions. This is just a general issue with any data structure.

Re: Gov.uk drops jQuery from their front end

#438
post #367

Earlier quoted context omitted.

> 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. This is a strawman argument. It's a biased view you hold. Because of that, you make up a story to match your biases around people who use such-and-such library don't think they need t…

> Who cares if it's a bit more code Well, Gov.uk for one, as per the article you're commenting on. As they pointed out: > Not everyone is tapping away on their 2022 MacBook Pro on a rip-roarin' broadband connection. GOV.UK has to be accessible to everyone, and that means keepin' it lean. > Here's a few of the greatest hits from Matt Hobbs on what GOV.UK noticed in removing jQuery: > - Less front end processing time o…

Yes, but that's a government site that's got an explicitly universal audience and is also pretty lightweight already.

If you're making a game, say, you may (may!) not care if Edna can't load it on a 1993 iMac, and you might be loading 40MB of resources, so another 24kB is not your pressing problem.

Engineering effort is always in short supply, and it is very expensive. Use it wisely. Sweeping judgements gleaned from very different products may not apply to your case.

Re: Gov.uk drops jQuery from their front end

#439

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…

Also, with the kind of smug tone op has posted his comment, I'm reasonably sure he doesn't understand that basic techniques fir x86 optimization have actually remain largely unchanged and what worked then also works reasonably well now, despite compiler improvements

Also you don't get good at assembly optimisation without understanding things like cache coherency and register allocations. New CPUs don't suddenly invalidate that ability to reason about what the problem might be and what might help (and what might not). Crucially, you already know how to adjust your existing skills to apply to new things.

Re: Gov.uk drops jQuery from their front end

#440

Earlier quoted context omitted.

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.

> I mean, you normally abstract these things with a helper fn or two, without importing the whole jQuery anyway. Add enough helper functions are you're at jQuery anyway. Looking at the jQuery source code, it manages a lot of edge cases that I don't really have time to figure out on my own. The DOM API isn't really designed that well for human consumption. https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeTy..…

> Looking at the jQuery source code, it manages a lot of edge cases that I don't really have time to figure out on my own.

Reminds me of the warning about rewriting old "messy" codebases. I am paraphrasing, but the upshot was "You know what those weird and ugly bits of code are? They're bug fixes, and they were earned through sweat and blood and years over a period of many, many years."

Post reply on HN