What Is It?
The big difference between pjax and Turbolinks is that with pjax it is necessary to specify which part of the page to be replaced. With Turbolinks, the entire body of the page is replaced.
How Does It Work?
The layout of assets on your server would have to support this. More than likely, your application probably doesn’t need many changes to support this. In cases where it doesn’t, the asset pipeline makes it very easy to concatenate your different assets. While you’re at it, add in some CSS spriting for fun and profit.
Behind the scenes, Turbolinks uses something called pushState to change the browser address. The address is replaced immediately with new information. In the case of Turbolinks, it will make the browser address mimic what it would normally be if you had clicked the link and had the normal page load process complete. Turbolinks can be taken advantage of anywhere internally, but for security reasons it will not fetch and replace with external sites.
Why Would I Use This in my App?
It’s no secret that users are more responsive and engaged on faster web pages. People are impatient and every millisecond counts. A big benefit of Turbolinks is that it doesn’t have a large amount of overhead to set up in your application. Since it replaces the entire body of a page, little really needs to be done to your markup to take advantage of it.
What if I don’t want to use it?
You can opt out by using the data-no-turbolink attribute on an existing link tag. Looking at the source, it doesn’t check for any particular value in the
data-no-turbolink attribute, only that it exists. The code to make a page load normally would look something like this:
<a href="/blog">My link</a>
<a data-no-turbolink="true" href="/blog">My link</a>
Another reason that you may not want to use Turbolinks is if you’re stuck supporting older browsers. In this case, though, you can leave it in your application and fallback will be graceful.
There’s a lot to be excited about with this project. With virtually no effort, your apps will receive a speed bump in response time. Are you pumped about trying out Turbolinks? Let us know in the comments.