Live data from Hacker News

Gov.uk drops jQuery from their front end

web.dev

51–60 of 458 posts

Re: Gov.uk drops jQuery from their front end

#51
post #13

Earlier quoted context omitted.

jQuery still offers a much nicer experience. The built-in dom apis are neither very elegant nor ergonomic. // jquery $(selector).on('click', fn) // vanilla js document.querySelectorAll(selector).forEach(el => el.addEventListener('click', fn) )

Is it worth adding the library (download size + script parsing & execution) for that though? At the very least there are some jQuery alternatives that are modular, smaller, and have less backwards compatibility like iirc zepto.

Yup. Because the size of the library and the execution time just isn't that big of a deal, it's something people seem to obsess over but it doesn't really matter much.

Re: Gov.uk drops jQuery from their front end

#52
post #40
post #34

Earlier quoted context omitted.

To add: jQuery is a pretty huge library for what it does. Talking both bundle size and execution speed. Not that the latter is noticeable for most cases, but it's still a cost. The question is: What for? The primary use case for it has been cross browser compatibility plus a bit of sugar. The former is _gone_ and the latter is easily replaced with a few lines of JS. Then there is an ecosystem of libraries and compone…

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.

or use https://axios-http.com/ for ajax stuff

Re: Gov.uk drops jQuery from their front end

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

Right. However, jQuery isn't just for cross-browser.

It provides a clean API for manipulating the DOM, as this site demonstrates (which is ironic): https://youmightnotneedjquery.com/

Personally, for simple sites, I aim for vanilla JS but use jQuery (cash, actually) where it makes sense - such as working on collections of elements.

Re: Gov.uk drops jQuery from their front end

#54

Earlier quoted context omitted.

For AJAX, jQuery is still simpler than vanilla JS.

Even fetch?

Definitely not Fetch. I don't believe anyone can argue that Fetch is more complicated.

I think this really seems to stem from a "I'm only used to jQuery, anything else is a big mental effort to learn and I'd rather stick with what I know".

I get it. Vanilla JS, if you're not used to it, is scary. But if you're advocating for jQuery "for simple interactions", and assuming it's simpler than vanilla JS, at some point you should ask yourself if you're just letting your skills stagnate, and staying stuck in the past. You owe it to yourself to update your skillset. If you decide you still need jQuery (e.g. maybe you need a plugin/library that requires jQuery), then fine. But at least you'll be making an informed decision, not a FUD-driven one.

Re: Gov.uk drops jQuery from their front end

#56

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.

Re: Gov.uk drops jQuery from their front end

#57

The bashing of jQuery comes from junior devs. Of course a VDOM is clearer, more productive (and less performant) however most webapps with a minimum of logic have many legitimate uses of native dom/jquery in addition to the VDOM. And the interaction is perfectly safe as long as you do native DOM in the right lifecycle method (mounted). jQuery is a pleasure to use and give us a lot of power/expressivity. More generall…

I do think that your complaint, while applicable to a lot of websites, is not specifically applicable to GOV.UK. They do everything to use plain HTML (and if possible no Javascript at all, but there are certain pages where Javascript is an absolute must like interactive maps), and they aren't using React but instead a special framework that is designed to minimise Javascript even to novice developers. Basically they've replaced jQuery with plain Javascript since that some older devices they're supporting (which jQuery is a better solution as it's bug-tested and optimised as much as possible) is dead.

Re: Gov.uk drops jQuery from their front end

#58

The bashing of jQuery comes from junior devs. Of course a VDOM is clearer, more productive (and less performant) however most webapps with a minimum of logic have many legitimate uses of native dom/jquery in addition to the VDOM. And the interaction is perfectly safe as long as you do native DOM in the right lifecycle method (mounted). jQuery is a pleasure to use and give us a lot of power/expressivity. More generall…

[deleted]

Re: Gov.uk drops jQuery from their front end

#59

The bashing of jQuery comes from junior devs. Of course a VDOM is clearer, more productive (and less performant) however most webapps with a minimum of logic have many legitimate uses of native dom/jquery in addition to the VDOM. And the interaction is perfectly safe as long as you do native DOM in the right lifecycle method (mounted). jQuery is a pleasure to use and give us a lot of power/expressivity. More generall…

Not sure you read the submission, but the move away from jQuery was not to move to anything "virtual DOM"/React/similar but rather that the functions provided by jQuery now have vanilla/"native" alternatives.

Re: Gov.uk drops jQuery from their front end

#60

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.

[deleted]
Post reply on HN