How can I check on the server whether a request is made by Turbo? aka „What happened to Turbolinks-Referrer?“
See original GitHub issueHello! I’m in the process of upgrading an app from Turbolinks to Turbo, and I wondered that happened to the Turbolinks-Referrer
header that was available before.
I’m using it as for a few optimizations, for example I’m sending my SVG sprite inline, but only on the first (non-Turbolinks) request. I’m using Flask, but the way this works is pretty straightforward:
@app.before_request
def before_request():
g.is_turbolinks = "Turbolinks-Referrer" in request.headers
and then, in my HTML templates, I can do:
<div style="display: none;" data-turbolinks-permanent id="global-svg">
{% if g.is_turbolinks %}
<!-- no svg because it's a turbolinks response -->
{% else %}
{{ insert_inline("sprite/sprite.svg") }}
{% endif %}
</div>
I noticed that Turbo Drive does currently not seem to send any special headers. I added this workaround in my JavaScript:
document.addEventListener('turbo:before-fetch-request', (event) => {
event.detail.fetchOptions.headers['Turbo-Referrer'] = window.location.href
})
I was just wondering if this was omitted on purpose, or if you didn’t get to it yet. I think it was really useful and I’d love to see it make a comeback! Thanks.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:10 (1 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We’re also interested in some way for the server to distinguish between a full page refresh and a request initiated by Turbo-Drive. Seems like adding a
Turbo-Drive
request header, in the spirit of theTurbo-Frame
header would be helpful.Any interest in this?
@danieldiekmeier ahhh, I misunderstood your problem, sorry for adding noise to the issue.