filter · Cache control
Extend cache (extend_cache)
- Category:
- Caching
- CoreFilters:
- Yes
- OptimizeForBandwidth:
- No
- Risk:
- Generally safe
extend_cache rewrites the URLs of stylesheets, scripts, and images to carry a content hash, giving each resource a .pagespeed.ce. URL, and serves those resources with a one-year Cache-Control: max-age. When the original file changes, its hash changes too: once the module’s cached copy of the original expires (origin lifetime, or ImplicitCacheTtlMs when none is set), the page points at a new URL. Live demo: extend_cache.
What it switches on
extend_cache is a compound name. Enabling it enables these 3
filters; each can be disabled on its own.
- extend_cache_css — Extend cache for CSS
- extend_cache_images — Extend cache for images
- extend_cache_scripts — Extend cache for scripts
How it works
When it helps and when it does not
It helps wherever the origin cannot set long cache lifetimes itself, which is common on shared hosting and legacy applications: first visits cache every static resource for a year, and repeat visits stop revalidating them. It does nothing for resources that already carry a fingerprint and a long max-age from the build pipeline, since those URLs are already immutable in practice. It also does not make HTML cacheable: the page itself keeps its own short lifetime, because the page is what hands out the new hashed URLs after a deploy.
How it decides
Only resources on domains the module is authorized to rewrite are candidates, and resources already rewritten by another filter (a minified stylesheet, an optimized image) already carry a content hash, so there is nothing to extend. The one-year lifetime works because the URL is derived from the bytes: changed content gets a new URL rather than new bytes at the old one, so visitors pick it up once they load a page that references the new URL. The name is compound: it switches on extend_cache_css, extend_cache_images, and extend_cache_scripts, and each member can be disabled on its own.
When to use it
- In CoreFilters, the default RewriteLevel: it runs unless you disable it.
- Risk rating on these docs: Generally safe.
Risks
-
HTML and the resources it references must share one configuration; a setup where two virtual hosts disagree on the same file can serve a hash that does not match. See Virtual hosts.
-
Verify with the
X-Mod-Pagespeedresponse header and a?PageSpeedFilters=-extend_cachecomparison; Is it working? has the steps.
Configuration
Enable it in the module configuration, at server, virtual-host or location scope:
Apache
ModPagespeedEnableFilters extend_cachenginx
pagespeed EnableFilters extend_cache;IIS (pagespeed.config)
pagespeed EnableFilters extend_cacheIt is on by default under CoreFilters; to turn it off:
ModPagespeedDisableFilters extend_cache # Apache
pagespeed DisableFilters extend_cache; # nginx
pagespeed DisableFilters extend_cache # IIS<!-- before -->
<link rel="stylesheet" href="/css/site.css" />
<!-- after: served with Cache-Control: max-age=31536000 -->
<link rel="stylesheet" href="/css/site.css.pagespeed.ce.HASH.css" />The sub-filters extend_cache_css, extend_cache_images, and extend_cache_scripts are included when you enable extend_cache, which turns on all three. Each can also be enabled individually with EnableFilters (for example, extend_cache_images alone).
On the worker
The worker runs its own pipeline, configured by flags. Its equivalent of this filter
is the
cache extension
transform. Always-on under pagespeed on;.
Scoping, ForbidFilters and the thresholds filters read:
Choosing filters
.
Live example
Rewrites resource URLs to content-hashed names so they cache for a year.
This filter changes how the page is structured or delivered, not its size, so the example shows a source diff rather than a byte or request reduction.
Frequently asked questions
- What does the extend_cache filter do?
extend_cacherewrites the URLs of stylesheets, scripts, and images to carry a content hash, giving each resource a.pagespeed.ce.URL, and serves those resources with a one-yearCache-Control: max-age. When the original file changes, its hash changes too: once the module's cached copy of the original expires (origin lifetime, orImplicitCacheTtlMswhen none is set), the page points at a new URL. Live demo: extend_cache.- Is extend_cache enabled by default?
- Yes.
extend_cacheis in CoreFilters, the default RewriteLevel, so it runs unless you turn it off withDisableFilters. - How do I turn off extend_cache?
- Add
ModPagespeedDisableFilters extend_cacheon Apache orpagespeed DisableFilters extend_cache;on nginx. On IIS, addpagespeed DisableFilters extend_cacheto pagespeed.config.
Related filters
- extend_cache_css — Extend cache for CSS
- extend_cache_images — Extend cache for images
- extend_cache_scripts — Extend cache for scripts
- trim_urls — Trim URLs
- extend_cache_pdfs — Extend cache for PDFs
- local_storage_cache — Local storage cache
- rewrite_domains — Rewrite domains
This page is drawn from the extend_cache entry on Cache control. Every filter in one table: PageSpeed filters.