Browser Caching Strategies
1 min read
- Authors
- Name
- Vijaykumar Rajendran
- @vijayrajendran_

Table of Contents
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
| Header | Purpose |
|---|---|
Cache-Control | How to cache |
Expires | When to expire |
ETag | Unique identifier |
Last-Modified | Last change time |
Faster page loads!