Saturday, June 11, 2016

How to disable URL rewriting by Google PageSpeed Modules

The PageSpeed modules are open-source server modules for Apache and Nginx that optimize your site automatically. They offer different packages which can be installed on your server. You can download packages here.

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:
ModPagespeedAllow wildcard_spec ModPagespeedDisallow wildcard_spec
pagespeed Allow wildcard_spec;
Disallow wildcard_spec;

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:
ModPagespeedDisallow "*/jquery-ui-1.8.2.custom.min.js"
ModPagespeedDisallow "*/js_tinyMCE.js"


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

If you don't have access to disable it for your site, you can add ?ModPagespeed=off to the end of your URL in the browser like this