Live data from Hacker News

I loved jQuery, and still do (2019)

withblue.ink

71–80 of 189 posts

Re: I loved jQuery, and still do (2019)

#71
post #49

Some people talk big about dropping jQuery and saving one request, yet they have a shipload of bloat elsewhere. Not using jQuery in and of itself is not an optimization of any kind. I use jQuery and my page has a perfect score in GTmetrix. If the goal is optimization, you have to consider the total package. Addititionally, jQuery loads on the first request and sits in local cache thereafter. And it could already be i…

It won’t be cached already. Safari, Chrome and Firefox all have partitioned cache now.

Re: I loved jQuery, and still do (2019)

#72
post #61

Every time anything about jQuery is posted, someone will inevitably post the "You might not need jQuery" site. [0] I look at that site and laugh. Is this supposed to be making the case ~against~ jQuery? Maybe the audience for that site are seasoned developers for whom the vanilla JS syntax is easily understood. Everybody else is going to look at those code snippets and think jQ is the way to go. For people that have…

I agree that the vanilla JS snippets seem hilariously more complicated, but simplicity isn't everything.

In a corporate environment, if "I need to include jQuery as a dependency" involves asking another team how to set up custom deployment or whatever, and that is the difference of days between deploying a feature or not, then I'll definitely take the hit of 10 more SLoC vanilla JS.

Re: I loved jQuery, and still do (2019)

#73
post #29

Earlier quoted context omitted.

This feels like a false equivalence; how many of those 2000s users were browsing the web on mobile compared to today?

Does 30kb of js really matter on modern phones and modern mobile internet?

If "modern" means fast, then no. If "modern" means what people are using in 2021, then possibly.

Re: I loved jQuery, and still do (2019)

#74
post #64

I agree with the author that jQuery was essential for the time. Abstracting away browser compatibility issues in the era of IE6 was a wonderful thing, for sure. The problem is jQuery has no business being used today unless you have to maintain legacy code. Even then I would deprecate jQuery wherever possible. Using jQuery for a "quick and dirty" application today is just terrible and it sends the message to green dev…

> If you like quick and dirty, just make sure you have a working Node.js environment and generate a simple project that supports Webpack or Parcel There’s nothing quick or easy about these steps. Linking to a jQuery CDN and getting working code immediately is easy.

I respectfully disagree. If you take 15 min to understand the basics it becomes trivially easy and the productivity you gain going forward is massive.

Re: I loved jQuery, and still do (2019)

#75

Earlier quoted context omitted.

This page gives a pretty good overview of why jQuery is still relevant: http://youmightnotneedjquery.com/ Requests have gotten better with "fetch", but unfortunately, the "modern" DOM API is quite bad in some parts, making lots of stuff unnecessarily verbose. On top of that, it's really odd that the DOM API is not compatible with for-of loops, which could have been a selling point.

>it's really odd that the DOM API is not compatible with for-of loops, which could have been a selling point. I'm not sure what you mean by that? querySelectorAll returns an iterable. Also, your link is outdated. It doesn't include the fetch API which has enjoyed wide support for quite a while now.

> I'm not sure what you mean by that? querySelectorAll returns an iterable.

Apparently my knowledge is outdated. Last time I tried to switch from jQuery to vanilla JS, the results of document.getElementsByTagName and others were not iterable with for-of.

Re: I loved jQuery, and still do (2019)

#76
post #51

Earlier quoted context omitted.

You can do const $ = document.querySelector; $('.elements').style.color = 'red'; Which is only marginally more verbose.

No you can't. $('.elements') in jQuery is more equivalent to querySelectorAll('.elements'). You can however do: document.querySelectorAll('a').forEach(a => a.style.color = 'red')

This is the only post that I see so far that touches on the real innovation and unique value of jQuery: operating on groups. Everybody can go ahead and tell me that using a forEach every time is trivial, or that I can just insert some transpiler step in my build pipeline to take advantage of X language's convenient syntax, but the bottom line is that people use jQuery because it continues to be easier. Thank you for your insight and great design sense John Resig! Still not bested after 15 years.

Re: I loved jQuery, and still do (2019)

#77
post #69

Yes Jquery does makes things easier than vanilla JS Best being $("#id") replacing document.getElementById("id"); Makes code look cleaner

You can define your own `$` function. This way you can have the clean code without the entire jQuery library function $(arg) { if (arg.charAt(0) == "#") { // HTML spec does not support ids to start with numbers [0] // (you may not need this conditional on your website) return document.getElementById(arg.slice(1)) } return document.querySelector(arg) } Using this function you can select your comment with $('#27677234'…

The HN js actually does just this. The file isn't very long but has some great functions at the top

https://news.ycombinator.com/hn.js

Re: I loved jQuery, and still do (2019)

#78
post #22

Earlier quoted context omitted.

I'm not happy about it, but the reality is that 120kB is small potatoes in the modern web world. Would it be better without, sure? But there are bigger fish to fry. If jQuery helps the developer achieve their design and development goals, that will play out better for the end-user. It's not ideal, but it's realistic.

If jQuery helps the developer achieve their design and development goals, that will play out better for the end-user. That's not the dilemma though. Developer can build solutions without jQuery. They'll be faster, smaller, and have fewer dependencies. Plus, if you're only using jQuery for DOM and events then it probably isn't helping you. Those are two areas where writing vanilla JS is can often be easier than writin…

jQuery versus vanilla DOM is slower, larger, and adds dependencies.

jQuery versus [framework of the month] is "faster, smaller, and [has] fewer dependencies". Simpler build, too, while still keeping you from having to worry about which browser supports what.

Depends on what the most likely alternative is, then.

Re: I loved jQuery, and still do (2019)

#79
post #61

Every time anything about jQuery is posted, someone will inevitably post the "You might not need jQuery" site. [0] I look at that site and laugh. Is this supposed to be making the case ~against~ jQuery? Maybe the audience for that site are seasoned developers for whom the vanilla JS syntax is easily understood. Everybody else is going to look at those code snippets and think jQ is the way to go. For people that have…

I can see where you're coming from, but just wanted to add a counterpoint.

I recently removed jQuery from a website, and the YMNNJQ website was one of the bits of info that gave me the nudge to do that. The website in question only used jQuery in a handful of places, it was one of the few third party libraries being used (so the % size savings was significant), and I'm fairly fluent with JS... The website simply hadn't gone through a major update in the past 5 or 6 years, and the browser landscape has shifted enough in that time that the pros/cons weigh differently now.

So I think there are scenarios where this info is sometimes useful in the "I might remove jQuery" sense, and not in the "wow, I'm definitely keeping jQuery!" sense.

Re: I loved jQuery, and still do (2019)

#80
post #29

Earlier quoted context omitted.

This feels like a false equivalence; how many of those 2000s users were browsing the web on mobile compared to today?

Does 30kb of js really matter on modern phones and modern mobile internet?

This kind of thinking is why software continues to get slower and slower despite incredible advances in hardware.
Post reply on HN