-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Describe the problem
As noted in #909 (comment), 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