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…
I loved jQuery, and still do (2019)
71–80 of 189 posts
Re: I loved jQuery, and still do (2019)
#72Every 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…
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)
#73Earlier 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?
Re: I loved jQuery, and still do (2019)
#74I 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.
Re: I loved jQuery, and still do (2019)
#75Earlier 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.
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)
#76Earlier 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')
Re: I loved jQuery, and still do (2019)
#77Yes 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'…
Re: I loved jQuery, and still do (2019)
#78Earlier 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 [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)
#79Every 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 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)
#80Earlier 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?