Ship fast with Rails 6 and Bootstrap v5

Posted March 08, 2021 ‐  2 min read

Rails without jQuery : a new journey has started

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…
  })
})

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.

Help needed 😊

If you enjoyed the article, you can :

  • Share the article on Twitter , or LinkedIn , or Reddit , it will stimulate the writing effort, thanks !
  • Subscribe to the newsletter, you'll be warned each time a new Rails tutorial is released : we start from the rails new command to fully understand a new concept.
  • Subscribe to the Bootrails Beta, it's a tool to launch new Rails apps.

Thanks to all,

David