Hash API routes for static builds
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
SvelteKit always fetches a new copy of a route's data when navigating to a new page or using sveltekit:prefetch. If the website was built using the static adaptor, we know the data is static and there is no need to refetch and check for updates.
If you visit https://svelte-demo.jamcart.io/, use dev tools to throttle the connection, and use the browser's back/forward buttons to navigate, then that delay becomes noticeable. This is not an issue for Next.js (https://react-demo.jamcart.io/), Nuxt.js (https://vue-demo.jamcart.io/), or even just static html (https://astro-demo.jamcart.io/).
Describe the proposed solution
Adopt Next/Nuxt's approach. Instead of writing files out to /api/my-endpoint.json, it could be instead rewritten to /_app/{ BUILD HASH OR TIMESTAMP }/api/my-endpoint.json. Then, developers can simply apply Cache-Control: public, immutable to everything inside of /_app.
Alternatives considered
For a static built, SvelteKit could just keep previous requests in memory and not force a refetch.
Importance
nice to have
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how the static adapter writes API route data and how SvelteKit fetches route data during navigation and prefetching. Compare the proposed hashed /_app output with the current static route paths and the caching behavior described in the issue. Done means static builds avoid unnecessary refetches while generated routes remain reachable and cacheable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100