I'm using sveltekit and trying to load static assets like css/js on my localhost, but it didn't cached like disk cache or memory cache, how can I resolve this? it should be cached by default right?
...
<link rel="stylesheet" href="/assets/css/open-iconic-bootstrap.min.css">
...
I already deploy it to vercel and still doesn't cached, I need help.
This is already using the cache, however it is being revalidated every time.
You can see from the response 304 (Not Modified) and the transmitted size (113 bytes) that the resource is not re-transmitted.
How caching of static files is handled in the end depends on the adapter being used and the deployment environment. E.g. with Node the mechanism for setting additional caching headers would be different from the mechanism for an Nginx file server.
For Vercel, you might want to read its article on caching. However, revalidating every time might not be a bad idea, that way you will not get stale data at least.
For Vercel, I create another configuration by creating vercel.json in my root folder :
{
"headers": [
{
"source": "/:path*",
"headers" : [
{
"key" : "Cache-Control",
"value" : "max-age=2592000, s-maxage=10"
}
]
}
]
}
https://vercel.com/docs/project-configuration#project-configuration/headers
"source": "/:path*",
means wildcard that matches all routes.