I set the max-age to 30 days but the Koyeb CDN clears the cache after 30-60 seconds.
Reproduction
- Deploy a (Next.js) app, set cache headers on the static assets like fonts, CSS, and JS files.
Something like:Cache-Control: public, max-age=31536000, immutable
orCache-Control: s-maxage: 2592000
Here is a way to cache the /asset
folder in Next.js:
Summary
const nextConfig = {
headers() {
return [
{
source: '/:all*(css|js|gif|svg|jpg|jpeg|png|woff|woff2)',
locale: false,
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000',
},
],
},
]
},
}
- Request them a couple times and there will be cache hits, great. But wait 60 seconds and all the files will be a cache miss.
A workaround:
- Add domain to Cloudflare and proxy requests through there.
- Cloudflare will respect the cache control headers and cache for much longer, even on the free plan.
Disadvantages of using Cloudflare on top of Koyeb:
- Adds 30-60 ms TTFB latency to all your requests. This is because it routes through the proxy first, then to your app.
- Does not clear the cache on redeploys like Koyeb does.
Docs:
Blog post:
I would appreciate if someone at Koyeb could confirm if this is a bug or intended behavior?