5 ms·
You may not need jQuery
- gabrielsroka 3y agoI agree with many of the principles here. See my comment from 3 weeks ago https://news.ycombinator.com/item?id=36328697 https://news.ycombinator.com/item?id=36328697 Many of those equivalents are not equivalent because jQuery can act on multiple elements. Also it's spelled JavaScript, not javascript.
- Tikao 3y agoI've been using jQuery without thought for a while. Interesting how much javascript can do on it's own now!
- PaulHoule 3y agoI remember getting into an argument with my boss in 2005 because I told him that I mainly used jQuery to avoid having to deal with browsers having entirely different APIs to do AJAX request and otherwise avoid learning all the details of Javascript that were different on different browsers. That’s not necessary today because so much has been standardized. I find the CSS-selector based model to be appealing but you can get so many “spooky action at a distance” problems and it particularly drives me nuts in React applications where application state (not necessarily React state) can be manipulated both in React and also by jQuery behind React’s back. People who are interested in declarative approaches are into HTMX and similar toolkits now.
- deleted 3y ago[deleted]
- StreamingCat 3y agoI think the css vs query selector debate really boils down to personal preference. Especially in combination with modern frontend frameworks, complex frontend libraries like jQuery can cause all sorts of chaos. I remember it breaking one of my personal projects a while back that was using AngularJS.
- dustymcp 3y agoWas it not abit of a sin to include jQuery in angularJS back then? It's been awhile :)
- ycombinatornews 3y agoSimilar thoughts in cheat sheet format https://youmightnotneedjquery.com/ https://youmightnotneedjquery.com/
- paradox460 3y agoI'd update this to say you DO NOT need jQuery. I haven't used it in almost 5 years, and can't say I've missed it
- cantSpellSober 3y ago> which to this day [the append() and prepend() functions jQuery provides] have no direct competitor in vanilla js The vanilla JS append() and prepend() methods? I understand there are differences w/these vs jQuery but, for discussion, why not use those? https://developer.mozilla.org/en-US/docs/Web/API/Element/prepend#prepending_an_element https://developer.mozilla.org/en-US/docs/Web/API/Element/pre...
- StreamingCat 3y agoMainly because the vanilla append/prepend functions require that you create an element first, then insert it at the desired position. The ease of use of jQuerys string to html node isnt matched by vanilla js in these functions. The closest you would get is this: https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML https://developer.mozilla.org/en-US/docs/Web/API/Element/ins... But the jQuery prepend/append functions are still easier to read and shorter to write.
- cantSpellSober 3y agoFair arguments; the selector engine is flexible and terse. $.html() was great but I prefer createElement() because it guarantees I'm working with valid HTML, vs $.html("my typo here"). Interesting the article uses innerHtml in its helper function, jQuery's .html() method itself includes the comment "See if we can take a shortcut and just use innerHTML" https://github.com/jquery/jquery/blob/4a13266efd262a92f05d86b71d715885de103e6d/src/manipulation.js#L262-L299 https://github.com/jquery/jquery/blob/4a13266efd262a92f05d86...
- lxe 3y agoThis article feels like it's 2011 again. You probably don't need jQuery now, BUT I think the "bandwidth" and "cpu" arguments of not using jQuery are less relevant now, even in slower networks and lower-end devices. A lower-end device of 2023 is more than capable of downloading a few kb's of jQuery. There are certainly niche use cases to optimize for, but they are getting more and more niche, as average performance of mobile devices improves.
- niels_bom 3y agoI used to also think lightly of bandwidth and cpu but then I read a few things that Alex Russel wrote and now I’m of the opinion that every kb matters. Lots of people worldwide have shitty networks and shitty phones. If a website is a bit heavy or has a bit too much JS it may as well not exist for them.