Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable InstaClick by default (#1162)
* Enable InstaClick by default It will be the new default for Turbo 8. You can always opt out by setting `<meta name="turbo-prefetch" content="false">` in the head of your HTML. * Don't prefetch any anchor links * Don't prefetch UJS links For compatibility with older apps that use UJS, we should not prefetch links that have `data-remote`, `data-behavior`, `data-method`, or `data-confirm` attributes. All of these behaviors are now usually implemented as buttons, but there are still some apps that use them on links. * Allow to customize check to opt out of prefetched links * Tweak documentation * 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