Browser Caching Strategies

1 min read

Authors
banner
Table of Contents

Browser Caching Strategies

Cache Static Assets

nginx
location ~* \.(jpg|css|js|png|gif|ico|svg|woff|woff2)$ {
    expires 30d;
    add_header Cache-Control "public, immutable";
}

Long-Term Caching

For files with version hash:

nginx
location ~* \.(js|css)$ {
    expires 1y;
    add_header Cache-Control "public, immutable";
}

No Cache for HTML

nginx
location / {
    add_header Cache-Control "no-cache, must-revalidate, public";
    try_files $uri /index.html;
}

Cache Headers

HeaderPurpose
Cache-ControlHow to cache
ExpiresWhen to expire
ETagUnique identifier
Last-ModifiedLast change time

Faster page loads!

© 2026 Vijay Rajendranbuilt with Next.js & Tailwind · deployed on Vercel