Skip to content

Commit

Permalink
Respect data-turbolinks-preload='false' attribute
Browse files Browse the repository at this point in the history
(But still preload if that attribute does not exist at all!)

See #536
  • Loading branch information
unhammer committed Nov 11, 2020
1 parent cea82e2 commit cef4824
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Guide/view.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ Preloading with InstantClick on hover will only happen with links that
1. Use the GET method
2. Do not link to an anchor or end in `#`
3. Actually link to a different url than `location.href`
4. Do not have an attribute `data-turbolinks-preload='false'`

(So putting an anchor on a link will let you selectively turn off preloading for that link.)
(So putting an anchor on a link, or explicitly setting the `data-turbolinks-preload` attribute to `false`, will let you selectively turn off preloading for that link.)

## JSON

Expand Down
10 changes: 6 additions & 4 deletions lib/IHP/static/vendor/turbolinksInstantClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ Turbolinks.SnapshotCache.prototype.delete = function(location) {
};

const preloadAttribute = function(link) {
return true;
const linkAttr = link.attributes['data-turbolinks-preload']
if (!linkAttr || linkAttr.value === 'false') {
const linkAttr = link.attributes['data-turbolinks-preload'];
if (!linkAttr) {
return true;
}
else if (linkAttr.value === 'false') {
return false;
} else {
return true;
}
}
};

const isNotGetMethod = function(link) {
return link.classList.contains('js-delete');
Expand Down

0 comments on commit cef4824

Please sign in to comment.