Cache static assets for a long time
अपडेट: 1 दिस॰ 2026
यह गाइड अभी अंग्रेज़ी में है।
What it means
Static files (CSS, JavaScript, fonts, images) are served with a short or missing cache lifetime, so returning visitors download them again.
Why it matters
Repeat visits are slower and bandwidth costs are higher than necessary.
How to fix it
- Give fingerprinted files (e.g. app.3f9c1.js) Cache-Control: public, max-age=31536000, immutable.
- Serve HTML with Cache-Control: no-cache plus an ETag or Last-Modified so browsers revalidate cheaply.
Configuration examples
nginx
location ~* \.(css|js|woff2|avif|webp|png|jpg|svg)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
}
Apache
<FilesMatch "\.(css|js|woff2|avif|webp|png|jpg|svg)$">
Header set Cache-Control "public, max-age=31536000, immutable"
</FilesMatch>
Any platform
Cache-Control: public, max-age=31536000, immutable
Check your fix
curl -sI https://YOUR_DOMAIN/path/to/app.js | grep -i cache-control
References
- https://www.rfc-editor.org/rfc/rfc9111
- https://developer.chrome.com/docs/lighthouse/performance/uses-long-cache-ttl