A List Apart

Menu
The A List Apart Blog Presents:

Choosing Vanilla JavaScript

by · · 19 Comments

Article Continues Below

A lot of JavaScript developers out there, myself included, love jQuery. And rightly so! Like any great tool, it makes our lives easier. When building something with a large amount of front-end code, like a robust site or application, jQuery is a powerful ally.

However, if you’re building a small- to medium-sized library, you should seriously consider using vanilla JavaScript. Sometimes it makes sense to put down the power screwdriver and use some good old-fashioned elbow grease.

You Might Not Need jQuery is a fantastic resource that is sure to come in handy in these situations. It matches up snippets of the jQuery code you know and love with their vanilla JavaScript counterparts. It’s a straightforward way to see exactly what jQuery is doing for you.

Seeing the code side by side is useful for both ends of this conversation (notice it’s called You Might Not Need jQuery, not You Don’t Need jQuery). The difference between selecting elements in jQuery and in vanilla JavaScript is not as large as the difference between animation code. If you’re heavily reliant on element selectors, you might opt to go with vanilla JavaScript. But if you’re making heavy use of animation, jQuery may be your choice.

Historically, jQuery has been a great tool because it handles all cross-browser issues itself. To that end, the makers of You Might Not Need jQuery explain:

Some developers believe that jQuery is protecting us from a great demon of browser incompatibility when, in truth, post-IE8, browsers are pretty easy to deal with on their own.

If you don’t use jQuery, you have a choice to make: either write the code to solve browser compatibility issues yourself, or build a progressively enhanced experience. After all, JavaScript shouldn’t be required to use what you build. Weigh the benefits of writing vanilla JavaScript (fewer requests with less data to load by not including jQuery, among others) against the fact that certain browsers won’t get the full experience. Like everything in our line of work, choose the route that’s right for you, your team, and what you’re building.

About the Author

19 Reader Comments

Load Comments