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?
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.
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.
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.
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.
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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With