in the configuration file.
- 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.
In Apache the default set of libraries can be found in
file, which is loaded along with
pagespeed.conf when Apache starts
up. It contains signatures for all the Google Hosted
Libraries. In Nginx you need to
pagespeed_libraries.conf from Apache-format to Nginx
$ scripts/pagespeed_libraries_generator.sh > ~/pagespeed_libraries.conf $ sudo mv ~/pagespeed_libraries.conf /path/to/nginx/configuration_files/
You also need to include it in your Nginx configuration by reference:
pagespeed_libraries.conf. Local edits will keep you
from being able to update it when you update PageSpeed. Rather than editing it
you should add additional libraries to your main configuration file:
The general format of these entries is:
ModPagespeedLibrary bytes MD5 canonical_url
pagespeed Library bytes MD5 canonical_url;
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.
Additional library configuration metadata can be generated with the help of
pagespeed_js_minify utility installed along with PageSpeed.
wish to replace. If this is stored in
library.js, you can generate
MD5 as follows:
$ pagespeed_js_minify --print_size_and_hash library.js
$ cd /path/to/psol/lib/Release/linux/ia32/ $ pagespeed_js_minify --print_size_and_hash library.js
If you're using the new
pagespeed_js_minify. If you're using the old minifier,
--nouse_experimental_minifier. (As of 188.8.131.52,
--use_experimental_minifier is default. Previously,
pagespeed_libraries.conf includes hashes for both
the old and new minifiers.
You can see the filter in action at
www.modpagespeed.com on this
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>
is not tagged with
the canonicalized library is deferred.
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 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