Skip to main content

filter · JavaScript filters

Canonicalize JavaScript libraries (canonicalize_javascript_libraries)

Category:
JavaScript
CoreFilters:
No
OptimizeForBandwidth:
No
Risk:
Dangerous set

Replaces a <script src> that matches a known library (recognized by size and hash through the Library directive) with the library’s canonical URL on a shared CDN, so visitors reuse a copy already in their browser cache. In the dangerous set: the module ships no library table of its own any more, cross-site caches are partitioned in current browsers, and a canonical URL you do not control is a dependency you do not control. Use it only with your own Library entries and your own CDN.

How it works

When to use it

  • In the dangerous set: no RewriteLevel enables it, not even AllFilters. It exists for testing and measurement, not for production traffic.
  • Risk rating on these docs: Dangerous.
  • Targets the Google Hosted Libraries CDN; listed as deprecated in these docs.

Risks

The JavaScript filters page lists no specific risks for this filter. If a page misbehaves with it, DisableFilters canonicalize_javascript_libraries 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 canonicalize_javascript_libraries

nginx

pagespeed EnableFilters canonicalize_javascript_libraries;

IIS (pagespeed.config)

pagespeed EnableFilters canonicalize_javascript_libraries
pagespeed Library 105527 ltVVzzYxo0 //cdn.example.com/js/prototype.1.6.1.0.js;
pagespeed EnableFilters canonicalize_javascript_libraries;

Scoping, ForbidFilters and the thresholds filters read: Choosing filters .

Live example

Redirects well-known library files to a shared, canonical, cacheable URL.

This filter needs configuration or content the public demo doesn't provide, so the example has no diff to show.

See the before and after, with the source diff →

Frequently asked questions

What does the canonicalize_javascript_libraries filter do?
Replaces a <script src> that matches a known library (recognized by size and hash through the Library directive) with the library's canonical URL on a shared CDN, so visitors reuse a copy already in their browser cache. In the dangerous set: the module ships no library table of its own any more, cross-site caches are partitioned in current browsers, and a canonical URL you do not control is a dependency you do not control. Use it only with your own Library entries and your own CDN.
Is canonicalize_javascript_libraries enabled by default?
No. canonicalize_javascript_libraries is in the dangerous set, which no RewriteLevel enables, not even AllFilters. Enable it by name, for testing and measurement only.
How do I enable canonicalize_javascript_libraries on Apache and nginx?
Add ModPagespeedEnableFilters canonicalize_javascript_libraries on Apache or pagespeed EnableFilters canonicalize_javascript_libraries; on nginx. On IIS, add pagespeed EnableFilters canonicalize_javascript_libraries to pagespeed.config.

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

Google Analytics, AdSense, Fonts and Hosted Libraries are Google products. We-Amp isn't affiliated with or endorsed by Google.

Search