Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion docs/building-features/turbolinks.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,21 @@ This definitely can make an app perform better, even if the JavaScript and style
1. Include turbolinks via yarn as shown in the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/blob/8a6c8aa2e3b7ae5b08b0a9744fb3a63a2fe0f002/client/webpack.client.base.config.js#L22) or include the gem "turbolinks".
1. Included the proper "track" tags when you include the javascript and stylesheet:

**For Turbolinks 5.x:**

```erb
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => 'reload' %>
```

NOTE: for Turbolinks 2.x, use `'data-turbolinks-track' => true`
**For Turbolinks 2.x (Classic):**

```erb
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
```

**Note:** If you're using modern Turbo (recommended), use `'data-turbo-track' => 'reload'` instead of `'data-turbolinks-track'`. See the "Using Turbo" section at the top of this document.

1. Add turbolinks to your `application.js` file:
```javascript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
</style>
<%= stylesheet_pack_tag('client-bundle',
media: 'all',
'data-turbolinks-track': true) %>
'data-turbo-track': 'reload') %>

<%# Used for testing purposes to simulate hydration failure %>
<% unless params[:skip_js_packs] == 'true' %>
<%= javascript_pack_tag('client-bundle', 'data-turbolinks-track': true, defer: false) %>
<%= javascript_pack_tag('client-bundle', 'data-turbo-track': 'reload', defer: false) %>
<% end %>
<%= csrf_meta_tags %>
</head>
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<%= yield :head %>

<!-- NOTE: Must use defer and not async to keep async scripts loading in correct order -->
<%= javascript_pack_tag('client-bundle', 'data-turbolinks-track': true) %>
<%= javascript_pack_tag('client-bundle', 'data-turbo-track': 'reload', defer: true) %>

<%= csrf_meta_tags %>
</head>
Expand Down
Loading