onurya.

Notes ·

Nginx Cache Headers for Static Assets

A clean Nginx rule to cache immutable JS, CSS, and font assets in the browser for one year.

When your build pipeline outputs content-hashed filenames (such as app.9f3a1c.css), browsers do not need to send 304 Not Modified revalidation requests on repeat visits. Use this Nginx rule to cache static assets immutably for one year:

location ~* \.(?:css|js|woff2|svg|png|webp|avif)$ {
    expires 1y;
    add_header Cache-Control "public, max-age=31536000, immutable";
    access_log off;
}

Important: Keep HTML documents excluded from long-lived immutable caching; otherwise returning visitors may receive stale markup after a new deployment. Pair HTML routes with Cache-Control: public, max-age=0, must-revalidate instead.