question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I check on the server whether a request is made by Turbo? aka „What happened to Turbolinks-Referrer?“

See original GitHub issue

Hello! 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:open
  • Created 3 years ago
  • Reactions:6
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
kendagriffcommented, Sep 16, 2021

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 the Turbo-Frame header would be helpful.

Any interest in this?

1reaction
JonathanLorimercommented, Apr 20, 2021

@danieldiekmeier ahhh, I misunderstood your problem, sorry for adding noise to the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found