You (probably) don’t need jQuery

When I started dipping my toes in this front-end thing mere sight of JavaScript gave me acute onset of nausea. Needless to say, I steered away from it as as you would when you see a nasty bug or a spider lurking around. Looking back now that was such a mistake.

A quick glance at Stackoverflow and you can easily see that many upcoming developers mix jQuery and JavaScript, equating former to latter. You gotta ask yourself why is that, why is – or rather is – jQuery a de facto synonym for JavaScript? This guy asked it right 6 years ago. Short truth is that jQuery is much easier to learn than starting from the scratch learning pure JavaScript. If we talk 6 years back, jQuery had much more abstract function names and condensed much of most used JS functionalities into, in most cases, one line of code. Documentation was good, community behind the infamous JavaScript library was growing.. All was well but there laid the trap.

I’m gonna quote Burke Holland here because it relates so much to me, and will probably to you too:

I got to a point in my development career where the first thing that I did with any project was add jQuery, even if I was just creating very simple projects and samples. I did this mainly so that I could just use the DOM selection utilities. Back in the day of older browsers, this was easier to justify, but modern browsers have this whole DOM selection thing already nailed down for you.

That was probably my biggest mistake, including jQuery for every trivial stuff, even for just a few lines of code, so I wouldn’t have to deal with hassle of selecting DOM elements “manually”. And why should I, when I can just include this little one liner of code and can use all the jQuery magic I can think of? That was my line of thinking and probably was yours as well. Problems arose when I would have to create something from scratch or couldn’t use jQuery as project dependency, I started sweating profusely and when I didn’t it was either banging my head on the desk or scratching it until it bled (not literally).

I’m not going to tell you why jQuery is better than vanilla JavaScript – or isn’t. Rather, you can learn from my example why you really don’t need jQuery for the project you are working on. Yes, it’s great if you have to support IE7 or IE8 but that was a thing of the past. If we’re talking 2013 or 2014 to stretch it, but let’s be real here for a moment – IE8 has a global usage of 0.42% on tracked web (according to Can I use website). If even now you have to support IE8 on your projects I think it’s time to think about a new gig. Now days, every major modern browsers (we’re talking IE9+) is capable of emulating jQuery functions that you love so much. Well, emulating is poor choice of word since jQuery is emulating vanilla JavaScript behavior but you get the point. If you really do need to support IE8, IE9 or IE10 there’s a great website which offers you a list of ready blocks of code that will work for those dreaded browsers. Check out You Might Not Need jQuery website.

We need to break dependency chain – we’re mostly using jQuery because of habit, because we’ve always done so and we’re used to it. But there’s a real chance you might not need it. Did you know that jQuery actually utilizes this thing called web API, browser’s implementation of JavaScript (EcmaScript) specification – and various other APIs? Ray Nicholus wrote an awesome book called Beyond jQuery, you can order it over atĀ Amazon, which I strongly suggest. For justĀ  a couple of bucks you will see that everything you do with jQuery can easily be done with browser’s native JS API without the use of whole library.

With the introduction of ES6 specification functions have become really abstract and stuff like arrow functions and string templates have made learning JavaScript much more fun. Wes Bos went a step further and wrote a free 30 day vanilla JS coding challenge in which he shows how it’s really simple to make cool stuff using only vanilla JavaScript.

In closing, learning jQuery before actually making an effort with JavaScript fundamentals really deferred my progress in JavaScript world. Not only was I limited to using simple jQuery functionalities (because advanced stuff meant using vanilla JS as well) but was dependent on the library in question. Don’t make the same mistake and not only will you see that in most cases you will not need a whole library to do some arbitrary selecting of elements and manipulating them in some way but your coding skills will hop to a whole new level, which will in return open myriad of possibilities. I’m not saying that I’ve seen the light and I’ll never touch the stuff again but ditching jQuery in some cases and taking a dip in JavaScript pool really did change my way of looking at JavaScript. I’m sure the same will be the case with you, if you’re willing to try.

Every time you use jQuery a rainforest tree dies.