Live data from Hacker News

Gov.uk drops jQuery from their front end

web.dev

71–80 of 458 posts

Re: Gov.uk drops jQuery from their front end

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

Re: Gov.uk drops jQuery from their front end

#73
post #40

Earlier quoted context omitted.

30kb minified and gzipped! Less than most hero images. It's a nice API for simple stuff. I think if you strip out the AJAX support it can get extremely tiny.

30kb gzipped is still 10x larger than Preact for reference

that doesn't make it an issue in any way, it's not a numbers competition unless you have a 56K

Re: Gov.uk drops jQuery from their front end

#74

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'.

Re: Gov.uk drops jQuery from their front end

#75
jQuery never did make the migration to being packaged/delivered as a modern (i.e. post-2015) JavaScript module. This precludes it from being used in a lot of modern JavaScript workflows.

No matter what the library itself provides, to use it you have to go back to working like how developers in 2014 and before used to work with JavaScript, so that's a very real consideration that the "I still like to use jQuery" folks never mention. Are they writing all of their code as pre-2015 'classic' JavasScript as well?

Re: Gov.uk drops jQuery from their front end

#76
post #6

Eh. Everyone hates on jQuery, but for most informational sites that's really all you need for basic interaction. Speed really isn't bad, and it's so straightforward that it's hard to mis-use at this point. I seem to have way more issues with newer frameworks/SPA if I'm not using chrome with no extensions. Makes me nervous dealing with important stuff like banking or government sites.

For basic interaction, you don't need anything but vanilla JS. Browsers have come a long way since the days where jQuery was almost necessary to deal with all of the minor differences/bugs in various browsers.

You can do quite a bit without Javascript too. A lot of websites don't need much more than simple menus.

Steve Gibson's site is an example:

https://www.grc.com/default.htm

Re: Gov.uk drops jQuery from their front end

#78
post #62

There's almost no point talking about javascript on HN with the amount of anti JS & anti framework rhetoric that happens here

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.

Re: Gov.uk drops jQuery from their front end

#79
post #18

The gains aren't massive — certainly not something any human using the site would notice (about 20ms faster to render pages for the average mobile phone user). Still good to remove unncessary dependencies, though.

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

Re: Gov.uk drops jQuery from their front end

#80
I don't mind so much gov.uk using jQuery, but I noticed recently that the UK government's 'parliamentlive.tv' has a dependency on jQuery loaded from Google's CDN, when there was a Google outage in the country I live in (I think it was something to do with routing on Vodafone's side, rather than an actual Google outage).

I see that's now removed, but Recaptcha is still there. The site works without it, but it seems a bit odd to me that by default, my data is shared by my government with a third party company when I want to participate in democracy online.

Post reply on HN