Code n00b: Fight for Your Right to jQuery

Code n00b: Fight for Your Right to jQuery

Code n00b: Fight for Your Right to jQuery

These days there is so very much blind, burning hate directed toward jQuery, Lodash and similar libraries. I get it — most of the functionality they were invented to provide we can now simply create with ECMAScript’s built-in standard functions. But: if you are familiar with jQuery architecture (i.e., anybody who learned JavaScript prior to, oh, 2017) and can spare a few kB, jQuery is still legit. Fight me.

Ouch, jeez, I didn’t mean literally. Put down yer dukes and listen up, because here’s my reasoning:  jQuery helped build the web we all know, love, and use 24/7 every day. It helped solve little issues like, oh, browser compatibility and those nice smooth transition effects devs loved long before CSS was advanced enough to handle the job. But the number one reason you — yes, you! — should have at least a glancing knowledge thereof? The fact that jQuery is just about everywhere. Yes, still.

Still unconvinced? Here are some numbers according to the HTTP Archive, which crawls the top 10,000 websites from the Alexa top sites on the internet (we free users can only see the top 500 Alexa sites for free). The archive then exposes all that data as a downloadable MySql database containing all kinds of interesting metrics, including libraries required by those websites.

In 2017, jQuery showed up in 80 percent of these. Four out of five of the top 10,000 websites all use jQuery! You may argue that this is because WordPress powers so much of the consumer internet these days, and that WordPress uses jQuery… so we non-Wordpress devs can just safely ignore it (as can, come to think of it, anyone unlucky or simply lazy enough to develop projects atop WP, but I digress). Then, however, you will need to explain to me why Bootstrap only shows up in 14 percent of those same crawled sites when Bootstrap and WordPress go together like snot and Kleenexes. So that’s not the reason for jQ’s internet omnipresence.

You may now be thinking smugly, “Oh not me, here in my bleeding-edge startup shop that only uses Vue pre-pre-release version 23 beta.” So yeah, maybe not you, not now. In a couple of years, though, you’ll more than likely be working someplace else. Like me, you could spend your first week realizing that your real job is not deploying your knowledge of built-in JavaScript methods…but rather figuring out which methods do what in jQuery in that legacy codebase you just inherited. And that, to your surprise, when you finally take a few hours to just freaking learn it already, using jQuery actually can save an appreciable amount of time even while writing fresh, new, “modern” JavaScript.

I’m not saying it’s the silver bullet or anything. jQuery is great for simple or reasonably contained projects. Large-scale apps with lots of contributors, though, you definitely want a more rigid framework like Vue or Ember — lest the freestylin’ world of jQuery leads you to build a Flying Spaghetti Monster of tangled and unmaintainable code.

  • jQuery still ships as the default JavaScript library for a lot of large projects (WordPress being one of them).
  • jQuery is fully open source and actively maintained
  • One of the biggest slams against jQuery is that it adds unnecessary file size to your site. And while it does add a load, the truth is this is more often than not insignificant. Even if it is not…
  • …A huge percentage of your visitors already have jQuery cached from a CDN. This means using jQuery is essentially free as far as your bandwidth is concerned. It won’t slow down the loading time of your website in any meaningful way.
  • Even if they don’t have it cached, jQuery Slim Minified + Gzipped is only about 27KB. Your HTML markup alone might be larger than this! If you want the full-featured version of jQuery, that’s only about 6KB more.
  • Most of all, developing in jQuery — instead of some more opinionated framework — can be genuinely creative and fun. Freestylin’, even.

There’s also the fact that jQuery lowers the bar to entry for code n00bs. Picture a newly minted developer ready to take the vanilla JavaScript training wheels off. It’s easy and not too intimidating for them to write (or, maybe more realistically copy and paste) some code that uses jQuery, then add the jQ library and immediately get the positive feedback of viewable results. Now picture this same wobbly novice trying to get up and running on, say, React. Even given the beauty of CRA (Create React App), the success — essential for encouraging newbies — is not as direct or immediate with “modern” frameworks that use import/export default, destructuring, etc.

Despite all these benefits, it’s become fashionable to bash on tha jQ, to the point where I heard one of my students — so new to JS they can barely write a for loop — crack a jQuery joke. That was when I decided to write this. You certainly don’t need jQuery to write modern JavaScript. Not anymore. Nor do you need to drop everything and learn it this instant if you don’t already sprechen zie jQuery.  But: jQuery is far from dead. It may be facing a long, slow inevitable decline as it, like all tech, gradually gets replaced. At this moment, however, it’s still in pretty robust health.

So! Not only is jQuery still relevant, it’s embedded in today’s web-like spat-out Skittles in basement rec room shag carpeting. And there’s a 100 percent chance you are going to come across it at some point. The smart thing to do would be to stop spreading knee-jerk jQuery hate… and maybe even put it to good use yourself.

 

Leave a Reply

Your email address will not be published. Required fields are marked *