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.

www.example.com/wp-content/themes/eatfit/images/xfoot-logo.png.pagespeed.ic.SWoJqa9Ly9.png

However, this can be restricted by using wildcards, using the directives:
Apache:
ModPagespeedAllow wildcard_spec ModPagespeedDisallow wildcard_spec
Nginx:
pagespeed Allow wildcard_spec;
pagespeed
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:
Apache:
ModPagespeedDisallow "*/jquery-ui-1.8.2.custom.min.js"
ModPagespeedDisallow "*/js_tinyMCE.js"

Nginx:

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