Rails 5.1 dropped jQuery dependency in default stack

Neeraj Singh

By Neeraj Singh

on June 20, 2017

This blog is part of our  Rails 5.1 series.

Rails has been dependent on jQuery for providing the unobtrusive JavaScript helpers such as data-remote, data-url and the Ajax interactions. Every Rails application before Rails 5.1 would have the jquery-rails gem included by default.

The jquery-rails gem contains the jquery-ujs driver which provides all the nice unobtrusive features.

But now JavaScript has progressed well such that we can write the unobtrusive driver which Rails needs using just plain vanilla JavaScript.

That's what has happened for the 5.1 release. The jquery-ujs driver has been rewritten using just plain JavaScript as part of a GSoC project by Dangyui Liu.

Now that the unobtrusive JavaScript driver does not depend on jQuery, new Rails applications also need not depend on jQuery.

So, Rails 5.1 has dropped jQuery as a dependency from the default stack.

The current jquery-based approach would still be available. It's just that it's not part of the default stack. You will need to manually add the jquery-rails gem to newly created 5.1 application and update the application.js to include the jquery-ujs driver.

It's worth noting that rails-ujs only supports IE 11+. Visit the Desktop Browser Support section of Basecamp to see the full list of all the supported browsers.

Browsers support without jQuery

We saw some discussion about which all browsers are supported without jQuery. We decided to test it ourselves on a plain vanilla CRUD Rails app. We tested "adding", "editing" and "deleting" of a resource.

We found that all three operations (adding, editing and deleting) to be working in following cases.

  • Win 7 - IE 9
  • Win 7 - IE 10
  • Win 7 - IE 11
  • Win 8 - IE 10
  • Win 8.1 - IE 11
  • Win 10 - IE 14 Edge
  • Win 10 - IE 15 Edge
  • Win 10 - Firefox 53
  • Win 10 - Chrome 58
  • Win 10 - Safari 5.1
  • Mac Sierra - Safari 10.1
  • Mac Sierra - Firefox 53
  • Mac Sierra - Chrome 58

API change for the event handlers

rails-ujs driver has changed the signature of the event handler functions to just pass one event object instead of event, data, status and xhr as in the case of jquery-ujs driver.

Check the documentation for the rails-ujs event handlers for more details.

Stay up to date with our blogs. Sign up for our newsletter.

We write about Ruby on Rails, ReactJS, React Native, remote work,open source, engineering & design.