Please, Stop Using jQuery

It’s Time to Move On

·

4 min read

Please, Stop Using jQuery

To many, jQuery is a relic of the past. But to newcomers and the unsuspecting, it may still seem like an attractive choice for quickly building interactive websites or web applications. Despite being so outdated, jQuery is still used in 94.8% of all websites that use a known JavaScript framework!

If you’re still using jQuery: it’s time to move on. In this article, we'll take a look at why developers are turning away from this old-school option in favor of vanilla JavaScript and newer libraries like React or Vue.

Back in the day, manipulating HTML elements was hard. You couldn't just call a function and have it select elements and add events. You had to actually dig into your code and type out all these crazy DOM methods. jQuery used to be a boon, but with a package size of over 1MB it's way too heavy for most websites these days. There are much more efficient ways to write JavaScript that don't involve downloading an entire library every time you want to manipulate the DOM…

jQuery is lazy

I know jQuery is easy; the entire reason the library was created was to make it easier to use JavaScript in ways that used to otherwise be difficult or impossible with vanilla JS.

There are some great things about using jQuery: it gives you access to lots of ready-made functionality, and it does many things better than what you used to be able to write yourself. But there are some major drawbacks that negate these benefits.

  • It’s bloated
  • It’s slow
  • It doesn’t support tree-shaking, which means that if you import jQuery into your project, all of its code will get loaded even if only a small chunk gets used

Use vanilla JavaScript

You don't need to use the jQuery library now that vanilla JavaScript can do almost anything it can. In fact with ES6 being widely supported, if you're still using jQuery then you should probably reconsider your development approach.

If you're new to JavaScript and are looking for a short path to master the basics of DOM manipulation, there are better resources than jQuery:

  • Mozilla's Developer Network has an excellent tutorial on writing JavaScript in which they teach you how to write vanilla JavaScript to manipulate HTML elements, and moves onto more advanced topics like event handling.
  • You should also read through MDN's list of different methods available on document objects—this will help familiarize yourself with some common patterns used by web developers everywhere.

If your site is already using jQuery and you’re looking for an easy way to migrate to vanilla JS, check out replace-jquery—it analyzes your project files and generates used jQuery functions with their pure JavaScript alternatives.

Use another front-end framework

I'm sure you've heard of React. It's currently the most popular front-end framework, and for good reason: it has a number of advantages over jQuery.

  • Flexibility: React is extremely flexible and can be used in any environment or framework, including with other libraries (such as Flux) to create complex applications.
  • Ease of use: React is easy to learn and use because it uses JavaScript to do its work instead of HTML/CSS alone like jQuery does. This also makes it easier for developers with varying degrees of coding experience because they don't have to learn another language; just JavaScript!
  • Speed and performance: Unlike jQuery, which slows down your website by adding extra code onto each page load, React only adds its own small amounts at runtime—and those are cached by browsers so you won't even notice them!

You don’t need it!

Seriously, you don't need jQuery anymore.

For a long time, jQuery was the go-to library for making JavaScript do cool things on your web page. But now we have native DOM APIs and other libraries that are often much easier to use than jQuery. You can probably get away with not using any libraries at all, but if you really want to use one, please just use one of these instead:

  • React - a view layer built with a virtual DOM and JSX, an extension of JavaScript
  • Vue - a progressive framework for building user interfaces based on components
  • Angular - Google's popular framework for building web applications

Conclusion

Please, stop using jQuery. It's not necessary, and it's locking you into an old way of thinking. If you're looking for a modern way to build your UIs, consider frameworks like React or Vue. If you really don’t want to work with plain JavaScript, try using NPM packages that support tree-shaking to reduce the size of your codebase and make it easier to maintain and update. I hope this helps anyone who wants more information about why they might want to start using something else!

Did you find this article valuable?

Support trav by becoming a sponsor. Any amount is appreciated!