Why disable Turbolinks?
So, you want to learn how to remove Turbolinks? Let’s go. We will first see how to do it on a specific page, and then on the whole Rails app.
Disable Turbolinks on a specific page
The tag for disabling Turbolinks has changed in Turbolinks 5, let’s see how it works now.
As per the documentation, you can disable it on a page by including
data-turbolinks="false" in a div on the page. All the links will be disabled. But you can re-enable Turbolinks on a link by setting data-turbolinks to true. Your links must be within that div:
<div data-turbolinks="false"> <a href="/">Turbolinks disabled</a> <a href="/" data-turbolinks="true">Turbolinks enabled</a> <a href="/">Disabled again</a> </div>
You can also disable it directly on the link, without the need for a div:
<a href="/" data-turbolinks="false">Disabled</a>
How to disable Turbolinks entirely in 3 steps
- In your Gemfile, remove
//= require turbolinks
- In app/views/layouts/application.html.erb, you’ll see these two lines:
You need to remove, on each line:
media: 'all', 'data-turbolinks-track': 'reload' and
It’s similar on Rails 4:
'data-turbolinks-track' => true.
Don’t forget to run bundle and restart your server.
If you were using the
gem 'jquery-turbolinks' before upgrading to Rails 5, delete the corresponding line in your Gemfile and
//= require jquery.turbolinks in application.js.
How to skip Turbolinks for a new app
Rails will install Turbolinks by default when you run
Rails new myapp, because in most cases it won’t be a problem. But you can easily opt out from Turbolinks by using the
That could avoid you some hard to debug issues. Especially when you are developing your app and don’t need that kind of optimization yet.