What is the best way to allowing caching of images in the public folder?
I saw in the documentation that next.js can’t cache assets in the public folder because they may change. But is there a way to override this? I’ve been trying to mess with the headers in the vercel.json configuration, but to no avail.
Expected behavior:
When requesting a svg or png from an external site, it will be cached for further uses.
Header: Cache-Control: public, max-age=3600, immutable
Actually behavior:
The image must be fetched everytime
Header: Cache-Control: public, max-age=0, must-revalidate
Tried using the following configuration in vercel.json:
{
"github": {
"silent": true
},
"headers": [
{
"source": "/(.*)\\.(png|jpg|jpeg|gif|webp|svg|ico)$",
"headers": [
{
"key": "Cache-Control",
"value": "public, max-age=3600, immutable"
}
]
}
]
}