Skip to main content

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.

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-Pagespeed response header and a ?PageSpeedFilters=-extend_cache comparison; Is it working? has the steps.

Configuration

Enable it in the module configuration, at server, virtual-host or location scope:

Apache

ModPagespeedEnableFilters extend_cache

nginx

pagespeed EnableFilters extend_cache;

IIS (pagespeed.config)

pagespeed EnableFilters extend_cache

It 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.

See the before and after, with the source diff →

Frequently asked questions

What does the extend_cache filter do?
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.
Is extend_cache enabled by default?
Yes. extend_cache is in CoreFilters, the default RewriteLevel, so it runs unless you turn it off with DisableFilters.
How do I turn off extend_cache?
Add ModPagespeedDisableFilters extend_cache on Apache or pagespeed DisableFilters extend_cache; on nginx. On IIS, add pagespeed DisableFilters extend_cache to pagespeed.config.

This page is drawn from the extend_cache entry on Cache control. Every filter in one table: PageSpeed filters.

Search