Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
canonicalize libraries: script to convert from Apache format to Nginx
Browse files Browse the repository at this point in the history
Merge of Vid's #533 with some fixes.
  • Loading branch information
jeffkaufman committed Oct 21, 2013
1 parent 6e86835 commit 7c15cd8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Expand Up @@ -101,6 +101,28 @@ X-Page-Speed: 1.6.29.5-...
Looking at the source of a few pages you should see various changes, such as
urls being replaced with new ones like `yellow.css.pagespeed.ce.lzJ8VcVi1l.css`.

### Use Google Hosted JS (Canonicalize Javascript Libraries)

This is handy when you want to allow some of the more common javascript files to
load from Google's servers. See [the
documentation](https://developers.google.com/speed/pagespeed/module/filter-canonicalize-js).

To make this work with ngx_pagespeed, run:

```bash
$ scripts/pagespeed_libraries_generator.sh > ~/pagespeed_libraries.conf
$ sudo mv ~/pagespeed_libraries.conf /etc/nginx/
```

In the Nginx.conf file above, right after you say `pagespeed on`; add this

```nginx
include pagespeed_libraries.conf;
pagespeed EnableFilters canonicalize_javascript_libraries;
```

Now most of your common JS files will load from `//ajax.googleapis.com/...``.

For complete documentation, see [Using
PageSpeed](https://developers.google.com/speed/pagespeed/module/using).

Expand Down
22 changes: 22 additions & 0 deletions scripts/pagespeed_libraries_generator.sh
@@ -0,0 +1,22 @@
#!/bin/bash
#
# Converts pagespeed_libraries.conf from Apache-format to Nginx-format,
# supporting the canonicalize_javascript_libraries filter.
# Inspired by https://github.com/pagespeed/ngx_pagespeed/issues/532
#
# Usage:
# scripts/pagespeed_libraries_generator.sh > pagespeed_libraries.conf
#
# Then have nginx include that configuration file and enable the filter
# canonicalize_javascript_libraries.
#
# Author: vid@zippykid.com (Vid Luther)
# jefftk@google.com (Jeff Kaufman)

URL="https://modpagespeed.googlecode.com/svn/trunk/src/"
URL+="net/instaweb/genfiles/conf/pagespeed_libraries.conf"
curl -s "$URL" \
| grep ModPagespeedLibrary \
| while read library size hash url ; do
echo " pagespeed Library $size $hash $url;"
done

0 comments on commit 7c15cd8

Please sign in to comment.