Fix guides · Performance
How to fix “Use efficient cache lifetimes”
Files the browser has to download again on every visit. How to set long cache lifetimes with Cache-Control, and what you can and can't change on Shopify, WordPress, Webflow, Wix, Squarespace and Next.js.
- Time to fix
- 15–45 minutes
- Skill needed
- Developer
- Who notices
- Returning visitors and anyone browsing several pages
Why it matters
When your server sends a file, it can tell the browser how long to keep a copy. With a long lifetime, the second page someone visits reuses your stylesheets, scripts, fonts and images instead of downloading them again.
Chrome expects files like these to be cacheable for at least 30 days. Files with a short or missing lifetime are re-checked or re-downloaded on every page view.
This mostly helps repeat visits and browsing from page to page, not someone's very first view.
“Latency matters far more than bandwidth to web performance, so avoiding network latency for key requests can dramatically improve user-perceived performance.”
Before you start
- Look at whose files your report lists. Files on your own domain you can usually fix. Files from other services (analytics, chat, ads, review widgets, your platform's own scripts) are cached however that service decides. Some use short lifetimes on purpose so their updates spread quickly; those are safe to leave.
- A long lifetime is only safe for files whose name changes when their content does, such as app.3f9a1c.js. If you cache /style.css for a year and then edit it, returning visitors keep the old version. Rename the file (or add a version) when you change it.
- Don't cache HTML pages for long; visitors would miss your updates.
Fix it on your platform
Shopify Managed by the platform
- Shopify sets the caching for theme files, images and its own scripts, and you can't change it. Some of Shopify's own scripts (addresses containing /shopifycloud/) have short lifetimes on purpose, so updates reach your store quickly.
- Other flagged files usually come from apps. Remove the apps you don't need; for the rest, the lifetime is up to the app's developer.
WordPress
- Many caching plugins have a browser caching option that sets long lifetimes for images, CSS and JavaScript. Turn it on.
- Without a plugin, set Cache-Control headers in your web server configuration, or ask your host to.
- WordPress adds a ?ver= number to theme and plugin files, which usually changes when they're updated, so long lifetimes are generally safe for those.
<IfModule mod_headers.c>
<FilesMatch "\.(css|js|woff2|webp|avif|jpg|jpeg|png|svg)$">
Header set Cache-Control "public, max-age=31536000"
</FilesMatch>
</IfModule>Webflow Managed by the platform
- Webflow sets the caching for your site's own files, and you can't change it.
- Other flagged files come from scripts in your custom code or embeds. Remove ones you no longer need.
Wix Managed by the platform
- Wix sets the caching for your site's own files, and you can't change it.
- Other flagged files come from apps or custom code. Remove ones you no longer need.
Squarespace Managed by the platform
- Squarespace sets the caching for your site's own files, and you can't change it.
- Other flagged files come from code injection, embeds or extensions. Remove ones you no longer need.
Next.js
- Files Next.js builds (everything under /_next/static/) already get a one-year immutable lifetime.
- Files in /public get max-age=0, because Next.js can't know when they change. For files you version yourself, such as fonts or images you rename on change, add a long lifetime with headers() in next.config.
async headers() {
return [
{
source: "/fonts/:path*",
headers: [{ key: "Cache-Control", value: "public, max-age=31536000, immutable" }],
},
];
},Any other site
- Give versioned files (names that change with their content) a one-year lifetime and the immutable flag.
- Give files that keep the same name a shorter lifetime, or rename them when they change.
location ~* \.(css|js|woff2|webp|avif|jpg|png|svg)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
}Check that it's fixed
- In Chrome, open DevTools → Network, reload, click a file and check its Cache-Control response header.
- Re-run your StudioLNC audit: only third-party files you can't control should remain.
Find every issue like this on your site
Free audit of performance, accessibility, SEO and security, with fixes for your platform.