Your web page loads faster when JQuery is preloaded in users' browser.
With the optimization, a browser will notice that your site is requesting the library from the same shared library provider as a previous site it visited, and will use the copy in its cache.
This optimizer spots external libraries using a hash signature using a configurable list of signatures stored in configuration.
- Most important, first-time site visitors can benefit from browser caching, since they may have visited other sites making use of the same service to obtain the libraries.
- There are no charges for the resulting use of bandwidth by site visitors.
Canonicalization configuration format
The library is contained in IISpeed's configuration file in the installation directory.
bytes is the size in bytes of the library after
minification by PageSpeed, and
MD5 is the MD5 hash of the
library after minification. Minification controls for differences in whitespace
that may occur when the same script is obtained from different
canonical_url is the hosting service URL used to
replace occurrences of the script. Note that the canonical URL in the above
example is protocol-relative; this means the data will be fetched using the same
https) as the containing
page. Because older browsers don't handle protocol-relative URLs reliably,
PageSpeed resolves a protocol-relative library URL to an absolute URL based
on the protocol of the containing page. Do not use
URLs in configurations that may serve content over
https, or the
rewritten pages will expose your site to attack and trigger a mixed-content
warning in the browser. Similarly, avoid using
https URLs unless
you know that the resulting library will eventually be fetched from a secure
page, as SSL negotiation adds overhead to the initial request.
You can see the filter in action on this example.
If the HTML document looks like this:
<HTML> <HEAD> <SCRIPT src="jquery_1_8.js"> </SCRIPT> <SCRIPT src="a.js"> </SCRIPT> <SCRIPT src="b.js"> </SCRIPT> </HEAD> <BODY> ... </BODY> </HTML>
jquery_1_8.js was an unminified copy of the jquery
b.js contained site-specific code
that made use of jquery, the page would be rewritten as follows:
<HTML> <HEAD> <SCRIPT src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </SCRIPT> <SCRIPT src="a.js"> </SCRIPT> <SCRIPT src="b.js"> </SCRIPT> </HEAD> <BODY> ... </BODY> </HTML>
The library URL has been replaced by a reference to the canonical minified
version hosted on
ajax.googleapis.com. Note that canonical
the above page will be rewritten as follows:
<HTML> <HEAD> <SCRIPT src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </SCRIPT> <SCRIPT src="http://www.example.com/a.js+b.js.pagespeed.jc.zYiUaxFS8I.js"> </SCRIPT> </HEAD> <BODY> ... </BODY> </HTML>
Only complete, unmodified libraries referenced by
tags in the HTML will be rewritten. Libraries that are loaded by other means
(for example by injecting a loader script) or that have been modified will not
You must ensure that you abide by the terms of service of the providers of the canonical content before enabling canonicalization. The terms of service for the default configuration can be found at https://developers.google.com/speed/libraries/terms.
The canonical URL refers to a third-party domain; this can cause additional DNS lookup latency the first time a library is loaded. This is mitigated by the fact that the canonical copy of the data is shared among multiple sites.
The initial request for a canonical URL will contain a
header with the URL of the referring page. This permits the host of the
canonical content to see a subset of traffic to your site (the first load of a
page on your site that contains an identified library by a browser that does not
already have that library in its cache). The provider should describe how this
data is used in its terms of service. The terms of service for the default
configuration can be found at
Again, this risk is mitigated by the fact that canonical libraries are shared
among multiple sites; a popular library is likely to already reside in the
Sites serving content on both
https URLs must
use protocol-relative canonical URLs as shown in the example above.
Fetching a library insecurely from a secure page exposes a site to attack.
Fetching a library securely from an ordinary page can increase load time due to