sveltejs / sveltejs/kit

Hash API routes for static builds

Open
#2,330 0 comments 8 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

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.