Adapters should add cache-control headers to static assets
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
As noted in https://github.com/sveltejs/kit/issues/909#issuecomment-1004128975, most adapters don't configure cache-control headers for the three categories of static assets — hashed (Vite output), static directory contents, and prerendered pages.
Describe the proposed solution
For hashed assets there's no real reason they shouldn't have cache-control: public, immutable, max-age=31536000.
For the contents of the static directory, it really ought to be configurable. This could be done on a per-adapter basis (e.g. there's a PR for adapter-cloudflare-workers here), but since it's a universal requirement I think it belongs in the main config. Straw man:
// svelte.config.js
export default {
kit: {
static: {
// cache everything in `static` for 1 hour
cache: 3600
// cache large images for one hour, small images for ten minutes, don't cache anything else
cache: ({ filename, size }) => {
if (filename.startsWith('images') {
return size > 1_000_000 ? 3600 : 600;
}
return 0;
}
}
}
};
Prerendered pages should adhere to whatever the cache-control header was at the time of prerendering. For some platforms it may be difficult or impossible to set cache headers for static assets, but here we can at least cache stuff in the browser with a <meta http-equiv> tag.
Alternatives considered
No response
Importance
would make my life easier
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 reading the linked issue #909 comment and the adapter-cloudflare-workers PR #1771 to understand the existing approaches. Then map how hashed assets, static directory contents, and prerendered pages are handled across adapters; done means the cache-control behavior and configuration scope are agreed for all three categories.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- infrastructure, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100