Do Turbolinks Apps Still Need SJR?
Have you ever wondered about the role of SJR in a Turbolinks-enabled app?
Turbolinks already handles so much out-of-the-box,
why would you ever want to manually code a
In this case, it’s hard to imagine a scenario that calls for a JS response, which raises the question…
has Turbolinks replaced SJR?
Nope, it hasn’t.
Turbolinks and SJR are perfect complements to each other because SJR can handle scenarios that Turbolinks cannot.
Turbolinks is built to handle
GET requests only;
it doesn’t handle XHR
which is exactly where SJR shines.
According to the Turbolinks maintainer:
When using Turbolinks, a normal redirect will generate a Turbolinks.visit() call, and otherwise there’s SJR.
In summary, Turbolinks will automatically handle your page-to-page navigation, whereas SJR can be used to handle XHR form submissions.
My next article will discuss the specific use cases where you should consider using SJR in your Rails app. Subscribe below so you don’t miss it!