Browser Caching Strategies

1 min read

Authors
banner

Browser Caching Strategies

Cache Static Assets

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:

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

No Cache for HTML

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!

© 2025 Vijay Rajendran