How to remove Turbolinks from Rails 4

Turbolinks is included by default in Rails 4.  It does do a good job of making pages loading faster, but not reloading all the javascript on each page.  This works fine a lot of the time, but there are cases where you may want to have page specific javascript load only on a single page.  Turbolinks can also cause other issues with javascript not working, in my case it created a bug where I had to refresh the page to get the javascript to load.  While there is a gem called jquery-turbolinks that is supposed to help with turbolinks javascript errors, it didnt work in my case.

So here is how to disable turbolinks in your Rails 4 app, which is what I had to do.

First, remove

gem 'turbolinks'

from your Gemfile, and run bundle install.

Second, remove the line

//= require turbolinks

from your application.js file.

Last, in your views > layouts > application.html.erb file, set the ‘data-turbolinks-track’ to false, or delete it altogether. Personally I like to leave as false, so its easy to add back in the future.

<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => false %>
<%= javascript_include_tag "application", "data-turbolinks-track" => false %>

And turbolinks is removed from your app. Now I did find a way to leave the turbolinks css in place, and only remove the javascript. This seemed to still work fine in my case. To do that, leave the turbolinks gem in the gemfile, just remove the require turbolinks line from the application.js file. (step 2 above) Then in the application.html.erb file, set the javascript turbolinks to false, but leave the css turbolinks to true. Although bear in mind I can’t confirm this will work in all situations.

<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => false %>

Credit here.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: