Why I Broke Up with jQuery

jQuery is like your cool older first boyfriend who you pretend is a good decision even though he doesn't understand your taste in movies and is jealous of your guy friends. Cut to six months later and you're still together, because honestly what's the alternative, pure JS and CSS? Nah, fuck that. You want fancy and convenient. 

The problem is you're a grown up now. You write grown up code with grown up frontend frameworks, and jQuery boyfriend has become this glaringly incongruous thing that you keep around because you met his parents and don't want to make him cry.

1evnp1.jpg

Here are a few reasons to move on to greener pastures:

1.  One less thing to load and possibly slow down UI performance

Native JavaScript is always going to be faster. jQuery of course uses pure JS underneath, but it does a lot of extra things too, like tests and comparisons on the text. Case in point.

2.  The DOM API is just fine for little things

Many of us, myself included, never bothered properly learning the DOM API. Can you blame us? jQuery is often cleaner, easier, more robust and takes care of cross browser issues. However, unless you require IE7 support, the selectors available to you in the Web API are generally adequate.

3.  The JS spec keeps evolving

If you can easily avoid using a library, you probably should, especially if doing so will encourage a deeper understanding and appreciation of a language. The pervasive idea that JavaScript inherently sucks and we need to throw a bunch of glitter on it to make it palatable is just whiny and wrong. ES6, ES7 and beyond are ever closing the gap between what we want JavaScript to do and what it can do.

4.  Manipulating the DOM can be an antipattern

With front end libraries like React, Angular and Vue, direct DOM manipulation is unnecessary and kind of gross. It really comes down to separation of concerns and maintainability. If you're going for modularity and scalability, jQuery ends up just being one more thing to worry about and introduce bugs when you make changes to your code.

5.  You don't need $.ajax()

Here is a great post on how JavaScript's native XMLHttpRequest compares to $.ajax(). I personally prefer to use the Fetch API, which is more intuitive and easier to read than XHR, and handles responses and callbacks with promises. It also has a number of built in methods to use on the returned content.

When to drunk text

At this point jQuery is probably happily married to someone who drinks white wine and thinks astrology is real. However, if you're working on a small project or plugin, and performance doesn't really matter, there's still a case for giving him a ring.

P.S. John Resig is a fucking god, and jQuery is one of the most mindblowingly impressive and influential contributions to web.