sveltejs / sveltejs/kit

`preloadData` should be able to cache multiple routes at a time

Open
#12,122 4 comments 30 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

Reading the docs and using preloadData, I had always assumed I could call it multiple times and that it would cache each route. I've actually been using it this way for months and never noticed somehow. Due to lack of documentation of this limitation, I was very confused for a while and it wasn't until I dug into the code that I confirmed my suspicions that the load cache can only store one route at a time.

Describe the proposed solution

I think preloadData should be able to cache multiple routes at a time. Perhaps the maximum number of routes to be cached could be set in the config or something. This would be a huge help for my app where many pages make lots of fetches that could be effectively hidden this way.

I understand that it isn't really desirable to cache a bunch of routes when you are hovering over links with data-sveltekit-preload-data="hover", but I think that when the dev calls preloadData manually, there is no reason to clear the other cached routes in that case. If the dev did want to clear the cache, maybe that could be an optional argument to preloadData or a separate function entirely, but I think that's overcomplicating it.

I think the simplest thing would be just to allow N number of routes to be cached at the same time, tweakable by the user via config.

Alternatives considered

No response

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 preloadData implementation and the load-cache behavior described in the issue. Trace how repeated manual calls and hover preloading interact, then define the cache limit and configuration behavior; the work is done when multiple routes can be cached as intended and the limitation or new behavior is documented and tested.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.