I’m trying to optimize image caching for my Kirby site (v4) which runs on Nginx with a public/ folder setup. I want to serve images in the frontend (especially those under /media/pages/…) with long-term caching headers, like:
Cache-Control: public, max-age=31536000, immutable
The Problem
Since both the frontend and the Panel use the same /media/pages/… URLs, I can’t distinguish between them on the server level (e.g. via Nginx location blocks).
Example Nginx config:
location ~* ^/media/.*\.(jpg|jpeg|png|webp|svg|gif)$ {
expires 1y;
add_header Cache-Control "public, max-age=31536000, immutable";
}
After applying this, images in the Panel stop updating properly, even after uploading a new one — the old cached version is still shown due to browser cache. If I open an image to set a focal point, the request results in an 404 error.
Question
Has anyone solved this in a better or more reliable way (without ugly Nginx workarounds like checking $http_referer)?
Thank you