Turning on turbolink

191 views Asked by At

After I've precompiled assets and uploaded them to CDN I decided to turn on turbolinks. They were kind of turned on before when I were precompiling assets, that is I had gem turbolinks in Gemfile and require turbolinks in application.js but in application.html I had data-no-turbolink instead of data-turbolinks-track" => true.

Now I change it to data-no-turbolink to data-turbolinks-track" => true and expect them to work in production on the my local machine but it seems they aren't. Visually it seems they aren't working and "initiator" in the browser isn't turbolinks.

I don't want to recompile the assets if it's not really needed because reuploading them to CDN takes a lot of time.

So do I have to recompile them? Or perhaps I just don't notice that they are really working already?

2

There are 2 answers

2
Ely On

Not easy with the sparse information you provide. But here are some notes worth considering:

About Turbolinks:

With Turbolinks pages will change without a full reload, so you can't rely on DOMContentLoaded or jQuery.ready() to trigger your code. Instead Turbolinks fires events on document to provide hooks into the lifecycle of the page.

You probably use jQuery? Read above link to understand. A good solution is this one: jQuery.turbolinks

... But if you have a large codebase with lots of $(el).bind(...) Turbolinks will surprise you. Most part of your JavaScripts will stop working in usual way. It's because the nodes on which you bind events no longer exist. ...

0
fylooi On

data-turbolinks-track is only for asset tracking (to make sure the loaded assets file is the latest). It does not affect whether Turbolinks is used for a particular link.

If turbolinks is installed, any internal link without data-no-turbolink will be loaded using Turbolinks UJS.

The following code will fire an alert if Turbolinks is running.

$(document).on('page:load', function(){ alert("Turbolinks is active"); });