sveltejs / sveltejs/kit

Prefetch timeout

Open
#3,787 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p2-nice-to-have prefetch
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

SvelteKit include the ability to prefetch pages while the user is hovering over a link.
However, a the prefetched data might not be relevant after a period of time, so when the user will click on the link, say after a minute, she will get old data.

Describe the proposed solution

I think the simple solution is to allow to specify timeout.
Either allow to specify timeout in a syntax similar to <a sveltekit:prefetch={timeout: (time in seconds)} ...>, or get the timeout from an optional "timeout" property in the return value of load() function, or even support both solutions.

A better/additional aprouch to the simple "timeout" property in my opinion, is to allow the developer to give a predicate:
function dataValidity(lastPrefetchedTime): boolean

Alternatives considered

The manual alternative would be to use some custom svelte action in the <a> tag which calls prefetch() manually and call it again if the user hover/click on the link after a certain amount of time.

Sadly, as far as I know, there is not even a way to invalidate the prefetched data manually. (the invalidate() works only for the currently active page acoording to the docs)

Importance

would make my life easier

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the prefetch() and invalidate() entry points and how load() data is handled. Compare the proposed timeout, load() return property, and predicate approaches before choosing a supported behavior. Done means prefetched data can be invalidated or refreshed according to a documented, tested API.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.