Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable InstaClick by default #1162

Merged
merged 6 commits into from
Feb 6, 2024
Merged

Enable InstaClick by default #1162

merged 6 commits into from
Feb 6, 2024

Commits on Feb 5, 2024

  1. 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.
    afcapel committed Feb 5, 2024
    Configuration menu
    Copy the full SHA
    09d9fc4 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    127fc18 View commit details
    Browse the repository at this point in the history
  3. 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.
    afcapel committed Feb 5, 2024
    Configuration menu
    Copy the full SHA
    1251953 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    5b866db View commit details
    Browse the repository at this point in the history
  5. Tweak documentation

    afcapel committed Feb 5, 2024
    Configuration menu
    Copy the full SHA
    bca14e4 View commit details
    Browse the repository at this point in the history
  6. 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")
    }
    ```
    afcapel committed Feb 5, 2024
    Configuration menu
    Copy the full SHA
    7327a95 View commit details
    Browse the repository at this point in the history