-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adapters should add cache-control headers to static assets #3194
Comments
This would be great. |
@Rich-Harris Shouldn't this return a cache-control string, instead of a max-age integer? |
Static assets are public by definition; there's no value in being able to mark them non-public. Perhaps it makes sense to expose Flexibility isn't always a good thing — cache-control headers can be a footgun. I'd argue it's a good thing, for example, not to expose the ability to inadvertently mark prerendered pages or |
There is an edge case here if you set Repro steps:
I've observed this issue with sleeping tabs on both Firefox/Win11 and Chrome/Android. Browser behavior is a bit fickle especially with tab hibernation that afaik doesn't have a "standard" per se, but it could hopefully be solved by setting meta tags. Since I've set |
Hi, any updates on this issue ? This is a real problem for production applications, no caching for static assets is just detrimental for performance. |
I'm also interested. Browsing the internet, I found this was a thing: kit/packages/adapter-node/src/handler.js Line 22 in 5970255
|
I came here due to Lighthouse reporting this problem for fonts. I would love to see it implemented. |
Same here, not having this feature impacts the lighthouse performance score negatively. It would be too lovely to see this feature implemented. |
As a workaround for now, it's recommended to have your assets processed by Vite so they get cached. For example: <script>
// The image and font are both cached.
import Image1 from './your-image.jpg';
</script>
<img src={Image1} />
<style>
@font-face {
font-family: 'Work Sans';
font-style: normal;
font-weight: 600;
/* src/routes/your-page/font.woff2 */
src: url('./font.woff2') format('woff2');
}
</style> |
A much required thing to solve the Caching issue on production for static assets. |
If the assets in the Users are most-likely using this directory because A root <!-- src/routes/+layout.svelte -->
<script>
import favicon from '$lib/static/favicon.png';
</script>
<svelte:head>
<link rel="icon" href={favicon} />
</svelte:head>
<slot /> It would also handle tackle these issues:
|
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Issue: #3 http://www.gnuterrypratchett.com https://kit.svelte.dev/docs/hooks "Requests for static assets — which includes pages that were already prerendered — are not handled by SvelteKit." sveltejs/kit#3194
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 foradapter-cloudflare-workers
here), but since it's a universal requirement I think it belongs in the main config. Straw man: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
The text was updated successfully, but these errors were encountered: