Live data from Hacker News

Gov.uk drops jQuery from their front end

web.dev

81–90 of 458 posts

Re: Gov.uk drops jQuery from their front end

#81
post #32

Earlier quoted context omitted.

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.

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.

Re: Gov.uk drops jQuery from their front end

#82
post #71
post #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 ... }

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.

Re: Gov.uk drops jQuery from their front end

#85

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.

Re: Gov.uk drops jQuery from their front end

#86
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

Just replace that one liner with a 15 liner.

Re: Gov.uk drops jQuery from their front end

#87
post #78

Earlier quoted context omitted.

There is also excessive praise for Gov UK design system that takes up half of the vertical space with cookie banner, flash messages, and navigation bar. It has so much useless negative space. I would give it 5 marks out of 10. It’s decent but not a bastion of good design.

Maybe not design but I would say it is a bastion of usability.

I prefer USWDS for usability: https://designsystem.digital.gov/

Gov UK design system is poorly usable. From color use to disorganized, scattered layout; it’s put together with haste and not much thought.

What it’s good at is looking sexy and minimal which captivates a lot of people.

Re: Gov.uk drops jQuery from their front end

#88

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

By "more efficient" it seems like you mean "less typing" because that is significantly less efficient in terms of downloaded code size and performance (the jQuery code calls the vanilla code.) PS. $ is an alias for document.getElementById so you can just do $('my_id').style.display = 'none'.

most people probably have jquery cached in their browser if you're pulling it from the google cdn

Re: Gov.uk drops jQuery from their front end

#89
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

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.

Re: Gov.uk drops jQuery from their front end

#90
AFAIK (I'm not a front-end dev but tried some) vanilla JavaScript has much of the things jQuery provided built-in nowadays yet they look much longer.

Now as JavaScript accumulated a lot of legacy stuff only kept for compatibility + also numerous verbally/syntactically sub-elegant APIs IMHO it is time to design a language which would simply be "better JavaScript" - clean, modern and elegant yet have no fundamental differences so it would be very easy to transpile by just string replace/mapping, essentially just a lightweight "syntactic sugar+discipline" layer. Then it can be integrated in browsers directly.

Post reply on HN