Skip to main content

Extend cache for scripts (extend_cache_scripts)

Category:
JavaScript
CoreFilters:
Yes
OptimizeForBandwidth:
No
Risk:
Generally safe

Core filter, one of the three members of extend_cache. Rewrites <script src> URLs to content-hashed .pagespeed.ce. URLs served with a one-year Cache-Control max-age: browsers keep scripts for a year, and a changed file gets a new URL, so there is nothing to purge. Use it when the origin cannot set long cache lifetimes itself; under CoreFilters it is already on through extend_cache.

How it works

Disabling it leaves extend_cache_css and extend_cache_images on. Live demo: extend_cache.

When to use it

  • In CoreFilters, the default RewriteLevel: it runs unless you disable it.
  • Also switched on by extend_cache.
  • Risk rating on these docs: Generally safe.

Risks

The JavaScript filters page lists no specific risks for this filter. If a page misbehaves with it, DisableFilters extend_cache_scripts turns it off for the scope you set it in.

Configuration

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

Apache

ModPagespeedEnableFilters extend_cache_scripts

nginx

pagespeed EnableFilters extend_cache_scripts;

IIS (pagespeed.config)

pagespeed EnableFilters extend_cache_scripts

It is on by default under CoreFilters; to turn it off:

ModPagespeedDisableFilters extend_cache_scripts   # Apache
pagespeed DisableFilters extend_cache_scripts;   # nginx
pagespeed DisableFilters extend_cache_scripts   # IIS

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 .

Frequently asked questions

What does the extend_cache_scripts filter do?
Core filter, one of the three members of extend_cache. Rewrites <script src> URLs to content-hashed .pagespeed.ce. URLs served with a one-year Cache-Control max-age: browsers keep scripts for a year, and a changed file gets a new URL, so there is nothing to purge. Use it when the origin cannot set long cache lifetimes itself; under CoreFilters it is already on through extend_cache.
Is extend_cache_scripts enabled by default?
Yes. extend_cache_scripts is in CoreFilters, the default RewriteLevel, so it runs unless you turn it off with DisableFilters.
How do I turn off extend_cache_scripts?
Add ModPagespeedDisableFilters extend_cache_scripts on Apache or pagespeed DisableFilters extend_cache_scripts; on nginx. On IIS, add pagespeed DisableFilters extend_cache_scripts to pagespeed.config.

This page is drawn from the extend_cache_scripts entry on JavaScript filters. Every filter in one table: PageSpeed filters.

Search