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
Live demo: canonicalize_javascript_libraries.
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_librariesnginx
pagespeed EnableFilters canonicalize_javascript_libraries;IIS (pagespeed.config)
pagespeed EnableFilters canonicalize_javascript_librariespagespeed 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.
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 theLibrarydirective) 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 ownLibraryentries and your own CDN. - Is canonicalize_javascript_libraries enabled by default?
- No.
canonicalize_javascript_librariesis in the dangerous set, which no RewriteLevel enables, not evenAllFilters. Enable it by name, for testing and measurement only. - How do I enable canonicalize_javascript_libraries on Apache and nginx?
- Add
ModPagespeedEnableFilters canonicalize_javascript_librarieson Apache orpagespeed EnableFilters canonicalize_javascript_libraries;on nginx. On IIS, addpagespeed EnableFilters canonicalize_javascript_librariesto pagespeed.config.
Related filters
- combine_javascript — Combine JavaScript
- defer_javascript — Defer JavaScript
- extend_cache_scripts — Extend cache for scripts
- include_js_source_maps — Include JS source maps
- inline_javascript — Inline JavaScript
- make_show_ads_async — Async AdSense
- outline_javascript — Outline JavaScript
- rewrite_javascript_external — Minify external JavaScript
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.