Skip to content

Make data-sveltekit-prefetch work with mousedown  #7289

@superboss224

Description

@superboss224

Describe the problem

At this time, data-sveltekit-prefetch works with mouseover on PC, while this behavior lets the browser prefetch a link sooner, it can lead to two issues :

  • prefetching more links than necessary when an user just hovers over big links without clicking on them, which can lead to additional useless requests, which are counted when using edge hostings like Cloudflare Workers or Deno, and which can lead to more data consumption
  • prefetching too soon, on a near-realtime application, fetching 500ms too soon can lead to outdated data (for example, if it's realtime stats app or a chat)

Describe the proposed solution

prefetching on mousedown still lets 100ms (duration of a click) to prefetch a page before the user's click ends, and if a website is hosted on a nearby server, or on the edge, the user will keep a feeling of immediacy, it will also do requests only when the user really wants to navigate to the page

To implement mousedown prefectch, we could have something like that for per-link or per-parent-element configuration:

<a href="/mypage" data-sveltekit-prefetch="mousedown"></a>

Or have a parameter like this in svelte.config.js :

prefetching: 'mousedown'

Alternatives considered

The alternative would be to prefetch programmatically with a custom directive, but it would require to reimplement a huge part of the prefetching syntax that sveltekit already provides, so I believe just having a way to opt-in mousedown prefetching would be a much better and cleaner way of using it

Importance

i cannot use SvelteKit without it

Additional Information

Prefetching on mobile already works on touchdown and does not need to offer another prefetch behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions