How to Leverage Browser Caching in WordPress (2026): Nginx, Apache and Cloudflare

Leverage browser caching in WordPress: Nginx expires rules set to 365 days, cache warning 231 KiB to 7 KiB

Disclosure: some links in this article (WP Rocket and FlyingPress) are affiliate links; read our affiliate disclosure. The Nginx, Cloudflare and plugin results I describe as mine come from my own test server; the rest is from official docs.

To leverage browser caching in WordPress, your server has to send a long Cache-Control: max-age (or Expires) header with static files: CSS, JavaScript, images and fonts. Then a returning visitor’s browser reuses those files from its own cache instead of downloading them again. On Apache a plugin can add the rules to .htaccess. On Nginx, plugins can’t, so you set it in the server config or at Cloudflare.

  1. Check your headers with PageSpeed Insights or curl.
  2. On Apache or LiteSpeed, turn on your cache plugin’s browser caching or add a mod_expires block to .htaccess.
  3. On Nginx, set expires in the server config.
  4. Check Cloudflare’s Browser Cache TTL, purge the cache and test again.

PageSpeed Insights now calls this audit “Use efficient cache lifetimes” (it used to be “Serve static assets with an efficient cache policy”, and before that “Leverage browser caching”). On my Nginx test site it flagged 231 KiB. After one small change to two Nginx rules, it flagged 7 KiB, and what was left were third-party files I can’t control. Here is exactly what I changed, how to check your own headers, and the mistakes to avoid.

Tested: WordPress 7.1.4, Kadence theme, Nginx on an aaPanel VPS in Hong Kong, Cloudflare proxied. Headers checked with curl and PageSpeed Insights from Dhaka on November 11, 2026. Tested by Dolon Bepari. Method: how we test cache plugins.

What browser caching is (and what it isn’t)

Browser caching means the visitor’s browser keeps a copy of your static files for a set time. The server decides that time with response headers. Cache-Control: max-age=31536000 means “keep this for one year”; max-age=43200 means 12 hours. While the copy is fresh, the browser doesn’t ask your server for it at all. When the lifetime runs out, the browser asks whether the file changed, using the ETag or Last-Modified header, and if it didn’t, the server answers 304 Not Modified without sending the file again.

It is different from the page cache that plugins like WP Rocket or WP-Optimize create. A page cache stores finished HTML on your server so WordPress doesn’t rebuild every page. Browser caching stores files in each visitor’s browser. A page cache makes the HTML arrive faster on every visit; browser caching removes downloads on repeat views. HTML itself should not get a long browser cache lifetime, or visitors won’t see your updates.

Cache layerWhere the copy livesWhat it helpsWho controls it
Browser cacheThe visitor’s browserRepeat visits and the next page viewCache-Control / Expires headers
Page cacheYour server (disk or memory)Time to first byte for everyoneA cache plugin or Nginx FastCGI cache
Edge (CDN) cacheCloudflare’s serversDelivery from a nearby locationCloudflare settings and cache rules

How to check browser caching in WordPress

There are three quick ways. Use at least the first two, because PageSpeed only shows the problem, while the headers show the cause.

  1. PageSpeed Insights: run your URL and open “Use efficient cache lifetimes” in the Insights section. It lists each file with its current Cache TTL and the estimated savings.
  2. curl: copy the URL of one CSS file and one image from your page source and run curl -s -o /dev/null -D - "URL" (on Windows use NUL instead of /dev/null, and curl.exe in PowerShell). It only reads the headers and changes nothing on your site. Look at cache-control and expires.
  3. Chrome DevTools: Network tab, click a CSS file, open Headers and read the Response Headers.

This is what my site sent before any change. The theme’s CSS file came back with max-age=43200 (12 hours), and a WebP image with max-age=14400 (4 hours):

curl headers for a theme CSS file showing Cache-Control max-age 43200, a 12-hour browser cache lifetime
curl headers for a WebP image showing Cache-Control max-age 14400 set by the Cloudflare Browser Cache TTL

PageSpeed agreed: “Use efficient cache lifetimes” showed an estimated 231 KiB of savings, with the WebP images at 4 hours and the CSS and JS files at 12 hours. The insight flags images, fonts, scripts and stylesheets whose lifetime is under 30 days, and it doesn’t skip third-party files (Chrome’s documentation recommends 30 days or a year). It became the default in PageSpeed Insights in June 2025, and Lighthouse 13 (October 2025) removed the old audit name.

PageSpeed Use efficient cache lifetimes audit with 231 KiB of savings: WebP images at 4 hours, CSS and JS at 12 hours

Why my lifetimes were short: the aaPanel defaults

Many control panels already add browser caching rules for you, and aaPanel does too. Its site config had two expires blocks: 30 days for gif, jpg, jpeg, png, bmp and swf, and 12 hours for JS and CSS. WebP wasn’t in the image list, so WebP files got no expires header from Nginx at all. Cloudflare then filled the gap with its own Browser Cache TTL, which on my zone was 4 hours.

aaPanel Nginx site config with the default expires rules: 30 days for older image types and 12 hours for JS and CSS
Cloudflare Browser Cache TTL setting at 4 hours in the Caching configuration

So the “problem” PageSpeed reported came from two defaults: an older panel rule that doesn’t list WebP, and a cautious Cloudflare setting. Neither was a WordPress problem, which is why a WordPress plugin couldn’t fix it.

How to leverage browser caching on Nginx

On Nginx you set browser caching with the expires directive inside a location block. If your panel already has blocks like aaPanel’s, edit those. Don’t paste new blocks underneath them: Nginx checks regex locations in the order they appear and uses the first match, so a second block lower down is ignored.

These are the two blocks I used in the test. I added webp, avif, svg, ico, woff and woff2 to the image rule and set both to 365 days. The odd (js|css)?$ pattern is aaPanel’s default; \.(js|css)$ is the cleaner form, but either works:

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|webp|avif|svg|ico|woff|woff2)$
{
    expires      365d;
    error_log /dev/null;
    access_log /dev/null;
}

location ~ .*\.(js|css)?$
{
    expires      365d;
    error_log /dev/null;
    access_log /dev/null;
}
aaPanel Nginx rules to leverage browser caching: webp, avif, svg, ico, woff and woff2 added and expires set to 365 days

In aaPanel: Website, your site, Conf (or Config), edit the two blocks, Save. aaPanel tests the config before it reloads Nginx. On a plain Nginx server, edit the site file in /etc/nginx/sites-available/ (or wherever your server block lives), run sudo nginx -t to check the syntax (it only reads the files and changes nothing), then sudo systemctl reload nginx to apply it. Keep a copy of the original blocks so you can paste them back if anything goes wrong.

If you use Cloudflare, purge its cache afterwards (Caching, Configuration, Purge Everything), otherwise Cloudflare keeps serving the files with the old headers. My first check after the change still showed the old header: it was a Cloudflare copy with an Age of 66,488 seconds. After Purge Everything, the new header came through.

Before and after: what changed

CheckBeforeAfter
Theme CSS (global.min.css)max-age=43200 (12 hours)max-age=31536000 (1 year)
WebP imagemax-age=14400 (4 hours, from Cloudflare)max-age=31536000 (1 year)
PageSpeed “Use efficient cache lifetimes”231 KiB estimated savings7 KiB estimated savings
What was flaggedEvery WebP, CSS and JS file, plus Cloudflare’s beacon and GravatarOnly Cloudflare’s beacon (1 day) and Gravatar (5 minutes)
PageSpeed mobile score9697 (run noise)
curl headers for the same CSS file after the change showing Cache-Control max-age 31536000
curl headers for the WebP image after the change showing a one-year max-age
PageSpeed Use efficient cache lifetimes after the change: only 7 KiB left from the Cloudflare beacon and Gravatar

The score barely moved, and that is expected (more on why below). What the change does help is visitors who come back after more than 4 hours (images) or 12 hours (CSS and JS). Before, their browser had to download those files again; now it keeps them for a year.

The remaining 7 KiB came from Cloudflare’s analytics beacon and the Gravatar image in the comments. Those are served from other companies’ domains, so their cache headers are theirs to set. You can’t fix them in Nginx. For third-party files in general, host them yourself where you can (Google Fonts, for example), delay the script until the visitor interacts with a plugin like WP Rocket or FlyingPress, or remove it. Cloudflare’s beacon comes from its Web Analytics, which you can turn off in Cloudflare if you don’t use it.

How long should browser cache lifetimes be?

One year is the usual value for static files (anything under 30 days gets flagged), and it’s safe for CSS and JS in WordPress because themes and plugins add a version to each file URL, such as style.css?ver=1.6.0. When the file changes, the version changes, the URL changes, and the browser downloads the new file. That’s why a long lifetime doesn’t trap old CSS after a theme update.

File typeLifetime I useWhy
CSS and JS (with ?ver=)1 yearThe version string changes when the file changes
Images, SVG, icons1 yearUploads rarely change; use a new file name if you replace one
Web fonts (woff, woff2)1 yearFonts almost never change
HTML pagesNo long browser cacheVisitors must see new posts and edits

The one catch is images. Files in your uploads folder have no version string. If you replace an image but keep the same file name, returning visitors may see the old one for up to a year. Upload the new image under a new name instead.

How to leverage browser caching on Apache (.htaccess)

On Apache and LiteSpeed servers, browser caching usually goes in the .htaccess file in your WordPress folder, using the mod_expires module. Most cache plugins write these rules for you (see the next section). If you add them by hand, back up .htaccess first and put the block above the # BEGIN WordPress section:

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/css "access plus 1 year"
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType text/javascript "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/avif "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"
  ExpiresByType font/woff "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
</IfModule>

mod_expires sets both Expires and Cache-Control: max-age. If you also want to add public or immutable to Cache-Control, that needs mod_headers and a Header set line. Nginx ignores .htaccess completely. If you are on Nginx and a guide tells you to edit .htaccess, it won’t do anything; use the Nginx method above.

Can a WordPress plugin do it? What I saw on Nginx

On Apache, yes: most cache plugins have a browser caching option that writes .htaccess rules. On Nginx, the same options do nothing, and the better plugins say so. Here is what I saw on my Nginx server while testing cache plugins:

PluginBrowser caching optionWhat happened on Nginx
Super Page CacheBrowser caching toggle (on)Wrote .htaccess only; CSS stayed at 12 hours. It shows separate Nginx instructions instead
WP-OptimizeStatic file headers tab (Apache only, per its FAQ)Detected Cloudflare and said Cloudflare handles browser caching
W3 Total CacheBrowser Cache module (expires and cache-control headers off by default)Writes its rules to an nginx.conf file that you include in your server config (I didn’t record the resulting headers)
WP RocketWrites .htaccess rules on Apache: CSS and JS 1 year, images and fonts 4 monthsCan’t edit Nginx config; its docs give a reference block to add yourself
LiteSpeed CacheBrowser Cache setting, off by default, 1-year TTLBuilt for LiteSpeed servers; I didn’t test it
Super Page Cache browser caching on Nginx: the CSS file still returns the 12-hour max-age from the server
WP-Optimize static file headers tab saying the site is on Cloudflare, which handles browser caching

So on Nginx, choose your cache plugin for page caching and front-end work, and set browser caching in the server. My best cache plugin for Nginx test covers how each plugin serves cached pages there, and best WordPress cache plugins ranks them on the same server.

Cloudflare Browser Cache TTL: set it or respect your server

Cloudflare has its own Browser Cache TTL setting under Caching, Configuration. On my zone it was 4 hours, and that’s the value my WebP images got, because Nginx sent none. Cloudflare’s default is 4 hours on every plan. The other cache layers, set up in order, are in my WordPress caching setup guide.

According to Cloudflare’s docs, it keeps your server’s value when that value is longer than the setting, and only overrides it when your server sends a shorter one or none at all. That is exactly what I saw: CSS kept Nginx’s 12 hours, WebP got Cloudflare’s 4 hours, and after my change both kept Nginx’s one year with the setting still at 4 hours. “Respect Existing Headers” goes one step further and never adds or changes the header. Either way, setting a sensible value in Nginx first means Cloudflare can’t shorten it.

If you can’t edit your server config (managed hosting, for example), Cloudflare can set the lifetime instead: create a Cache Rule that matches your static file extensions and set its Browser TTL to override the origin with one year. Don’t apply a long browser TTL to HTML pages.

One plugin changed this for me without asking. When I connected Super Page Cache to Cloudflare, it switched my zone’s Browser Cache TTL from 4 hours to “Respect Existing Headers”, so the Nginx values became the ones visitors got. It set it back when I disconnected. If your headers change after installing a Cloudflare-connected plugin, check this setting first. More Cloudflare settings for WordPress are in my Cloudflare settings guide.

What can go wrong (and how to fix it)

  • Duplicate location blocks: a new block below an existing one is ignored. Edit the existing block.
  • Old image after replacing it: same file name plus a one-year lifetime means some visitors keep the old copy. Upload under a new name.
  • CSS without a version string: if a plugin loads CSS or JS without ?ver=, a long lifetime can keep an old file after an update. Shorten that file type or ask the plugin author to add a version.
  • Security headers disappear: if you add add_header Cache-Control inside a location, Nginx stops inheriting the add_header lines from the server block there. The expires directive doesn’t have that side effect.
  • Nginx won’t reload: a typo in the config. Paste your saved original blocks back and save again.
  • Headers didn’t change: Cloudflare is still serving old copies. Purge Everything, then check with curl again.

After any change, check that pages still update for logged-out visitors. My WordPress changes not showing guide walks through every cache layer if something looks stuck, and cf-cache-status explained helps read Cloudflare’s headers.

Does browser caching improve your PageSpeed score?

Not directly. Google’s Lighthouse scoring docs say only the metrics (First Contentful Paint, Speed Index, LCP, Total Blocking Time and CLS) make up the Performance score; insights such as “Use efficient cache lifetimes” don’t count. A few guides claim otherwise, but the score can’t see a cache that a first visit never uses.

In my test the score moved from 96 to 97, which is within normal run-to-run variation. The real benefit is for people: the second page a visitor opens, and their next visit, reuse files they already downloaded. That covers every page after the first and every return visit.

If your first-visit speed is the problem, browser caching won’t solve it. Look at server response time first (how to reduce TTFB in WordPress), then page weight. A cache plugin with Remove Unused CSS and Delay JavaScript, such as WP Rocket or FlyingPress, helps there.

FAQ

How do I enable browser caching in WordPress?

Send long Cache-Control max-age (or Expires) headers for static files. On Apache, a cache plugin or a mod_expires block in .htaccess does it. On Nginx, set the expires directive in your server config, because Nginx ignores .htaccess. If you use Cloudflare, check its Browser Cache TTL too.

What does Use efficient cache lifetimes mean in PageSpeed Insights?

It is the current name of the old Leverage browser caching audit. It lists static files whose cache lifetime is short and estimates how much a returning visitor would not need to download if the lifetimes were longer. On my site it dropped from 231 KiB to 7 KiB after I set one-year lifetimes in Nginx.

How long should browser cache lifetimes be?

One year (max-age=31536000) for CSS, JavaScript, images and fonts is the usual choice. It is safe for CSS and JS in WordPress because file URLs carry a ?ver= version that changes when the file changes. Don’t give HTML pages a long browser cache lifetime.

Does browser caching improve PageSpeed score?

Not directly. PageSpeed tests your page with an empty cache, so browser caching can’t make that run faster. My score went from 96 to 97, which is normal variation. Browser caching speeds up the second page view and repeat visits.

Why can’t my cache plugin fix browser caching on Nginx?

Most plugins write browser caching rules to .htaccess, which only Apache and LiteSpeed read. On my Nginx server, Super Page Cache’s browser caching option left CSS at 12 hours. You need to add expires rules in the Nginx config, or let Cloudflare set the lifetime.

Can I fix third-party files like Google Analytics or Gravatar?

You can’t change their headers, but you can host some files locally (Google Fonts, for example), delay scripts until the visitor interacts, or remove them. On my site the only files left in the audit were Cloudflare’s beacon and a Gravatar image.

Is browser caching the same as a cache plugin?

No. A cache plugin mainly stores finished HTML pages on your server (page cache). Browser caching stores static files in each visitor’s browser. Most sites need both, plus Cloudflare’s edge cache if they use it.

Related Guides