Restricting Rewriting Via Wildcards: Allow and Disallow

Restricting and Controlling PageSpeed optimization rewriting

By default, all HTML files served by your server and all resources (CSS, images, JavaScript) found in HTML files whose origin matches the HTML file, or whose origin is authorized via Domain, will be rewritten. However, this can be restricted by using wildcards, using the directives:

pagespeed AvoidRenamingIntrospectiveJavascript off

These directives are evaluated in sequence for each resource, to determine whether the resource should be consider for rewriting. This is best considered with an example.

Example 1: Excluding JavaScript files that cannot be rewritten

Some JavaScript files are sensitive to their own names as they traverse the DOM. Therefore any rewriting on these files is invalid. We cannot cache-extend them or minifiy them. When such files are identified, we can exclude from the rewriting process via:

pagespeed Disallow "*/jquery-ui-1.8.2.custom.min.js" pagespeed Disallow "*/js_tinyMCE.js"

Example2: Specifying explicitly which types of files can be rewritten

By default, every resource referenced by HTML from authorized domains is rewritten, as if there was an implicit

pagespeed Allow "*"

at the beginning of every configuration. To change the default to be exclusive, issue

pagespeed Disallow "*"

and then follow it with which files you want to include. For example:

pagespeed Disallow "*" pagespeed Allow "http://*example.com/*.html" pagespeed Allow "http://*example.com/*/images/*.png" pagespeed Allow "http://*example.com/*/styles/*.css" pagespeed Disallow "*/images/captcha/*"

The later directives take priority over the earlier ones, so the Captcha images will not be rewritten.

Note: Wildcards include * which matches any 0 or more characters, and ?, which matches exactly one character. Unlike Unix shells, the / directory separator is not special, and can be matched by either * or ?. The resources are always expanded into their absolute form before expanding.

Note: The wildcard will be matched against the full URL including any query parameters. For example, if you want to match URL http://example.com/index.jsp?test=xyz you could use

pagespeed Allow "*.jsp*"

If you were to omit the trailing *, then URLs with query-params would not match.

These directives can be used in location-specific configuration sections.

Note: The names in wildcards are not evaluated with respect to the location specific configuration. The wildcards are evaluated against the fully expanded URL. So if you want to match js_tinyMCE.js you must prefix it with its full path, including http:// and domain, or use a wildcard, as shown above.