DEV Community

Cover image for RIP jQuery: An alternative for modern browsers
Anthony Delgado
Anthony Delgado

Posted on • Edited on

RIP jQuery: An alternative for modern browsers

RIP jQuery

Two years ago, at the first ever Code Newbie meetup, I had the chance to meet the creator of jQuery, John Resig. At the time I was really starting to double down on my Full Stack Javascript / MongoDB, React, Node journey, coming from a PHP/MYSQL/jQuery world. It was that night when the creator of jQuery got up on stage and told us that he no longer uses the library he created and instead focuses only on React when I told myself it was time to double down on modern Javascript libraries.

Listen, I love jQuery.

jQuery is great, it has allowed me to create amazing front end project, win hackathons and manipulate the dom to my heart's content. But sometimes you get to the point in a mans life that it is time to move on to bigger and better things. So I took the deep dive into the world of React and Node and I didn't look back. jQuery will always have a special place in my heart.

But jQuery is an old dog in a javascript world full of cheetahs and jaguars. It was created when IE6 was the latest browser and IE7 was the upgrade everyone was waiting for. It was release before Google Chrome was even a thing and Adobe Flash was the primary way people created interactive websites. jQuery was revolutionary for it's time, but it has been over 10 years since it's inception.

Which begs the question....

What if jQuery was written today?

Meet Cash. Today I was viewing the source of a friend of mine and reviewing some code and I came across an interesting Javascript library called Cash. Cash is a super small library built for modern browsers (Chrome, Firefox, Safari and Internet Explorer 9+) that provides jQuery style syntax for manipulating the DOM. Utilizing modern browser features to minimize the codebase, developers can use the familiar chainable $ methods at a fraction of the blot. While Cash does not promise to replicate 100% of the features of traditional jQuery it does come close, covering most day to day use cases such as adding / removing / toggling classes and parsing strings of html.

Learn more about the project here: https://www.npmjs.com/package/cash-dom

Is it time that the $ dollar sign made a come back?

Tools like React and Angular are great for modern web applications but do feel like overkill for simple landing pages.

Let me know what you think in the comments section below.

Top comments (10)

Collapse
 
thebouv profile image
Anthony Bouvier

I'll have to take a look at Cash a little more. I definitely think there is a place for jQuery and Cash. Way too often I hear about people choosing Angular or React for even the simplest projects which is super over-engineered.

If you're looking to build a simple site, not an app, you might just want to stick to vanilla since you're talking about modern browsers anyway.

I suggest giving youmightnotneedjquery.com/ a look. Maybe you don't even need Cash. :)

Collapse
 
chinmayj93 profile image
Chinmay Joshi

youmightnotneedjquery is really good. Thanks!

Collapse
 
thedigitalorchard profile image
The Digital Orchard • Edited

I'm a heavy jQuery plugin user, so I don't think Cash could replace jQuery in my framework, but what would be great is if Cash was a proxy in front of jQuery so the same $ handle worked for both. Requests would fallback to jQuery if Cash could not handle a request.

That way, $('selector').plugin(); would still work, by first hitting Cash, and then passing on to jQuery.

In my own code, I always use the non-shortcut jQuery handle, but I'm sure many plugins use the shorter $, which I don't have any control over. So this graceful fallback would let us take advantage of Cash and jQuery in one fell swoop.

Do you think the fallback behaviour would take away any performance/optimization benefits that Cash brings to the table, if we're loading jQuery anyway?

Collapse
 
bennadel profile image
Ben Nadel

I'm looking to replace jQuery with something smaller, but with a similar, clean API. So far, I'm thinking either Cash as you pointed out, or something like Umbrella. Currently comparing my current jQuery usage to the APIs of these newer libraries to see which would be the smallest lift.

Collapse
 
hexydec profile image
Hexydec

Although jQuery had got bloated over the years, the API is still a thing of beauty. I too wondered what jQuery would look like now (2018).

I wanted to be able to just include the bits I was using and nothing else, so I wrote Dabby.js, a lightweight modular jQuery clone written in ES6. See npmjs.com/package/dabbyjs.

Collapse
 
azuryu profile image
Azuryu

I used to use Zepto instead of jQuery. Though a downside is that it didn't got updated for a long while so using it in the future isn't safe anymore. Do I want to use an old library that doesn't fix issues anymore in a new project?

For simple things like class maniuplation I have my own $ wrapper as you can't do much wrong doing element.classList.add() for every element in the collection. But if I need more while limited in allowed file size (e.g. ad developing) I may need an alternative. Cash looks quite interesting and I'll take a looke into it.

Collapse
 
nuxodin profile image
Tobias Buschor

domProxy is a good alternative to jQuery.
Basically it's a NodeList with exactly the APIs elements have (using Proxies).
And some more handy apis like "nextAll('.selector')":
github.com/nuxodin/domProxy

Collapse
 
funkybob profile image
Curtis Maloney

How does it compare to Zepto ? zeptojs.com/

Collapse
 
gregj profile image
Greg-J

If jQuery were written today they certainly wouldn't have omitted ajax/get/post functionality...

Collapse
 
dbpalan profile image
dbpalan

The cost to use and the cost to maintain a production site is too high. As a result a good track record of the library / framework is more important than how powerful is it.