-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
turbo:before-prefetch
event
To allow for more fine-grained control over when Turbo should prefetch links. This change introduces a new event that can be used to cancel prefetch requests based on custom logic. For example, if you want to prevent Turbo from prefetching links that include UJS attributes, you can do so by adding an event listener for the `turbo:before-prefetch` event and calling `preventDefault` on the event object when the link should not be prefetched. ```javascript document.body.addEventListener("turbo:before-prefetch", (event) => { if (isUJSLink(event.target)) event.preventDefault() }) function isUJSLink(link) { return link.hasAttribute("data-remote") || link.hasAttribute("data-behavior") || link.hasAttribute("data-method") || link.hasAttribute("data-confirm") } ```
- Loading branch information
Showing
4 changed files
with
16 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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