Question

If I have a page that should never be cached and should always be retrieved from the server, how can I get turbolinks to do this when the user presses the back button? Will it just obey cache-control directives from the http response?

Was it helpful?

Solution

This has changed in Turbolinks 5, now you need to set this at the <head> level for a page to not be cached:

<head>
  ...
  <meta name="turbolinks-cache-control" content="no-cache">
  ...
</head>

Reference: https://github.com/turbolinks/turbolinks#opting-out-of-caching

OTHER TIPS

You can do the following to have turbolinks always fetch the page from the server for all pages (which at least in my case is the desired behaviour, so on clicking the back button the page is updated, too):

// js
Turbolinks.pagesCached(0);

Or, according to the doc to disable it for one site, simply add a data-no-transition-cache attribute to any element, so for example on the site you do not want to be cached add it to the body:

<body data-no-transition-cache>...</body>

You cannot to disable turbolinks effect after the user visited turbolink enabled page and even though you disabled turbolinks, when user pressed back button, maybe browser cached page will be displayed.

Latter part is not escapable, but formatter part is ease to escape by force making normal link by setting data-no-turbolink to the link which leads to always need to be retrieve page like this

<div>
  <a href="retrieve_always.html" data-no-turbolink>Special Page</a>
  <a href="normal_page.html">NormalPage</a>
</div>

and also, you can set data-no-turbolink more globally

<div data-no-turbolink>
  <a href="retrive_page1.html">Retrive page 1</a>
  <a href="retrive_page2.html">Retrive page 2</a>
</div>

In these cases, all retrieve needed page is cached by browser not by turbolinks and because of that, back button pressed handling delegated to the browser.

Short answer is no, you can't disable showing a cached copy of a page when the back button is pressed. That behavior would differ from the default behavior of browsers, which Turbolinks tries as best as possible to mimic.

If you go to any website, click a few links, and then press the back button, you'll notice the browser displays a cached copy. As far as I know that can't be disabled at the browser-level.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top