Skip to content
← Blog

How to Set Up Browser Cache Headers for Static Assets

speed Feb 8, 2026 2 min read

What the cache headers check tests

SiteCurl examines the HTTP response headers for static assets (CSS, JavaScript, images, fonts) and checks whether they include Cache-Control or Expires headers with reasonable durations. Assets served without cache headers, or with very short expiration times, fail the check.

Why it matters

When a visitor loads your site, their browser downloads HTML, CSS, JavaScript, images, and fonts. Without cache headers, the browser downloads all of these again on the next page view or return visit.

With proper caching, the browser stores static files locally and skips the download on subsequent visits. This makes page transitions and return visits significantly faster. For sites with many pages sharing the same CSS and JavaScript, the difference is substantial.

How to fix it

Nginx

Add cache headers for static file types:

location ~* .(css|js|jpg|jpeg|png|gif|svg|woff2|woff|ttf)$ {
    expires 1y;
    add_header Cache-Control "public, immutable";
}

The immutable directive tells the browser this file will never change at this URL (common when using fingerprinted filenames like app-abc123.css).

Apache

Add to your .htaccess:

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
</IfModule>

CDN caching

Most CDNs (Cloudflare, CloudFront, Fastly) respect the Cache-Control header from your origin server. Set long cache durations on the origin, and the CDN will cache accordingly.

Cache busting

Long cache durations work best with fingerprinted filenames. When you deploy new CSS, the filename changes (e.g., app-v2.css), so browsers fetch the new version. Most build tools and frameworks handle this automatically.

If you cannot fingerprint filenames, use shorter cache durations (1 week or 1 month) and accept that some visitors will see stale assets briefly after a deploy.

How to verify the fix

Check headers with curl:

curl -sI https://yoursite.com/assets/style.css | grep -i cache-control

You should see Cache-Control: public, max-age=31536000 or similar. A SiteCurl scan checks cache headers on all detected static assets.

Cache headers work alongside compression and image optimization to improve page load speed.

Start a free trial to audit cache headers across your site.

See what's slowing your site down

Measure Core Web Vitals, find render-blocking resources, and get a speed fix plan.

Start 7-Day Studio Trial

No credit card required.

We use cookies to understand how visitors interact with our site. No personal data is sold.