Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get turbolinks to always fetch a page from server

Tags:

turbolinks

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?

like image 404
Mohamed Hafez Avatar asked Apr 08 '13 13:04

Mohamed Hafez


People also ask

What does Turbolinks do with your browser's history?

Turbolinks saves a copy of the current page to its cache just before rendering a new page. Note that Turbolinks copies the page using cloneNode(true) , which means any attached event listeners and associated data are discarded.

How does Turbolinks work?

Turbolinks Overview It works by intercepting all link clicks that would navigate to a page within the app, and instead makes the request via AJAX, replacing the body with the received content. The primary speedup comes from not having to download or parse the CSS & JS files again.

How do I enable Turbolinks?

6.1 How Turbolinks Works The only thing you have to do to enable Turbolinks is have it in your Gemfile, and put //= require turbolinks in your JavaScript manifest, which is usually app/assets/javascripts/application.

What is Turbolinks gem?

If you're a Rails developer, chances are that you know Turbolinks. Turbolinks is a flexible and lightweight JavaScript library aimed to make your navigation through webpages faster. Turbolinks improves webpage performance by substituting the common full-page loads for partial loads in multi-page applications.


2 Answers

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

like image 118
tirdadc Avatar answered Sep 30 '22 09:09

tirdadc


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>
like image 29
Markus Avatar answered Sep 30 '22 08:09

Markus