+1 (617) 7782998 |

Restricting and Controlling PageSpeed optimization rewriting

Restricting Rewriting Via Wildcards: Allow and Disallow

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://**.html"
pagespeed Allow "http://**/images/*.png"
pagespeed Allow "http://**/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 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.

Restricting PageSpeed from combining resources across paths

By default, filters that combine multiple resources together are allowed to combine multiple resources across paths. This works well much of the time, but if there are location-specific access controls or path-specific cookies associated with JavaScript files, then you may need to turn off this feature.

pagespeed CombineAcrossPaths off

This directive can be used in location-specific configuration sections.

Restricting PageSpeed from rewriting URLs of introspective JavaScript

Filters that change URLs of JavaScript files are at times incompatible with JavaScript code that does string-manipulation on its own URL. To avoid problems with introspective JavaScript files, PageSpeed can be configured to skip URL-rewriting for such files. PageSpeed uses simple heuristics to determine whether a JavaScript file is introspective.

This affects filters rewrite_javascript, combine_javascript, inline_javascript, extend_cache, and extend_cache_scripts.

This feature is on by default, but for many sites these heuristics are too conservative and prevent optimizations that would actually be safe. To turn it off:

pagespeed AvoidRenamingIntrospectiveJavascript off

This directive can be used in location-specific configuration sections.

Limiting the maximum generated URL segment length

The maximum URL size is generally limited to about 2k characters due to Internet Explorer: See . Nginx doesn't apepar to have a limit here but Apache servers by default impose a further limitation of about 250 characters per URL segment (text between slashes). When running under Apache PageSpeed circumvents this limitation, but if you employ proxy servers in your path you may need to re-impose it by overriding the setting here. The default setting is 1024.

pagespeed MaxSegmentLength 250
ModPagespeedMaxSegmentLength 250
pagespeed MaxSegmentLength 250;

This directive can be used in location-specific configuration sections.

Limiting the maximum size of a resource to optimize

A resource with large content takes a long time and a large amount of memory to process. You can specify the maximum length (in bytes) of the content for PageSpeed to optimize. The default setting is -1, which means content of all lengths will be optimized.

pagespeed MaxCacheableContentLength -1

This directive can be used at the server level.

Signing pagespeed resource URLs

Note: New feature as of IISpeed 2.0 /

PageSpeed can be set to automatically cryptographically sign and verify resource URLs. Turning on resource signing will cause any resource requested without the proper signature to return 404 Not Found or 403 Forbidden depending upon the InPlaceResourceOptimization setting. This option can be used to reduce the attack surface for denial of service attacks.

pagespeed UrlSigningKey signature_key_string

Resource signing can also be turned on, but not enforced, which may be used for the transition period of moving a site from unsigned resourced to signed resources. In this mode, signed URLs are generated and accepted, as well as URLs with no signature and URLs with invalid signatures.

pagespeed AcceptInvalidSignatures true

This directive can be used at the server level.

Share View Comments
Some content on this website represents a modified version of the official Google PageSpeed documentation