Prefetch timeout
See original GitHub issueDescribe 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
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (7 by maintainers)
@Christian-E once #6924 is released
invalidate
will also invalidate prefetched data.We recently made a change such that instead of returning
maxage
fromload
, you return acache
object. One idea that occurs to me is adding aprefetchTimeout
property (name subject to bikeshedding, obviously) that, ifmaxage
isn’t specified, defaults to the globalconfig.kit.prefetchTimeout
(which defaults to some number of milliseconds — say 5000 for the sake of argument).I think that makes more sense than putting it in the attribute, since there’s no reason you’d ever have different values for two links that pointed to the same page.