Rails without jQuery : a new journey has started

Posted March 8, 2021 - tagged ruby-on-rails  ‐  2 min read

I have never worked *without* jquery. I have never followed the 'no-jquery' hype. But let's face it, even the giants are removing jQuery from their stack. Rails 6 now works without jQuery. Bootstrap 5 now works without jQuery. So as a developer, when I see this kind of trend, I wonder if it's not time to reconsider.

It's not about the size

jQuery is not that big. A few dozen of KB are nothing compared to the high-definition background video the designer requires you to add on the landing page.

However I understand the dev's frustration. Browsers are able to handle what jQuery does. Thus, using a 3rd party lib instead of a standard, native solution seems a "code smell" at first glance.

It's about habit

The jquery API is very intuitive. And shared across the globe. Around 2014, as far as I can remember, it was used by about 90% of the websites (I can't remember the source, sorry).

The plugin ecosystem was extremely wide.

At that point, I really wonder why jQuery was not seen as a web standard, and directly integrated into browsers. W3C could have decided it years ago.

Anyway, now, it's too late. Almost everything can be another way, just by following standard web API.

The problem

Now web browser comes with an API that is :

  • a lot more verbose
  • a lot less intuitive

Let's take an example :

// jQuery
$('.button').click(function() {
  // code…
})

// JavaScript equivalent
[].forEach.call(document.querySelectorAll('.button'), function(el) {
  el.addEventListener('click', function() {
    // code…
  })
})
  • You can code the jQuery version "right now", with limited jQuery knowledge.
  • You can hardly write the JavaScript version without referring to a guide or cheat sheet.

The ecosystem has evolved. I now often see tiny libraries that are shipped with ES6 only in mind. I already talked about Rails and Bootstrap, but even my favorite accessibility lib, originally built with jQuery, has now a vanillaJS alternative.

The solution

Maybe it's time for Rails app to try to be entirely built without jQuery. I know, there are many apps (and devs) who already jumped into this "danger zone" a long time ago.

This means more verbose JavaScript. On the other hand, the rise of Hotwire means less JavaScript anyway.

For the private admin backend, I still embed jQuery, where I feel that the need for performance and standardisation is not as important.

About us

👉 We are 2 Ruby-on-Rails lovers. By building BootrAils, we hope we will help you to launch your Startup idea (really) faster.
Take care ! Health first. 🙏
Shino & David.