Last active
April 27, 2020 22:25
-
-
Save jschee/ca883be5cd8fba6eecadb2733760b507 to your computer and use it in GitHub Desktop.
Turbolinks meta head tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#In application layouts | |
<head> | |
<% if content_for(:turbolinks_cache) %> | |
<%= yield(:head) %> | |
<% end %> | |
</head> | |
#On view page | |
#For hard reload | |
<% content_for :turbolinks_cache do %> | |
<meta name="turbolinks-visit-control" content="reload"> | |
<% end %> | |
#For no-cache | |
<% content_for :turbolinks_cache do %> | |
<meta name="turbolinks-visit-control" content="no-cache"> | |
<% end %> | |
#For no-preview | |
<% content_for :turbolinks_cache do %> | |
<meta name="turbolinks-visit-control" content="no-preview"> | |
<% end %> | |
https://github.com/turbolinks/turbolinks/issues/418 | |
Hi @asmith26 | |
<meta name="turbolinks-visit-control" content="reload"> tells Turbolinks to perform a full page load. Upon visiting a page containing that meta tag, Turbolinks will call window.location.reload() to request a completely fresh page from the server. All assets will be reloaded and evaluated. This tends to be used when dealing with a third-party library which is incompatible with Turbolinks in some way (see #311 for the background on this). | |
The turbolinks-cache-control directive determines the caching behaviour. Setting this to no-cache on a given page means that the page will never be cached. Returning to the page by tapping Back/Forward, or by clicking a link, will result in Turbolinks fetching the page via XHR, merging the <head> and replacing the <body>. Because of this, it is more efficient than a full page load (but not as quick as rendering a cached copy). It is useful if you have a particular page that changes frequently, and you want to be certain that it is up-to-date whenever visited. | |
Do they perform the same thing (i.e. always fetch page from server)? | |
They will both result in fetching and rendering pages from the server, yes, but turbolinks-visit-control … reload does a full page reload, whereas turbolinks-cache-control … no-cache will render the page via JavaScript. | |
Hope that clarifies things. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment