Configuring PageSpeed Filters

PageSpeed Configuration

Rewrite Level

PageSpeed offers three base levels of optimization: PassThrough, CoreFilters and OptimizeForBandwidth. The CoreFilters set contains filters that Google's PageSpeed team believes are safe for most web sites. The OptimizeForBandwidth setting provides a stronger guarantee of safety and is suitable as a default setting for use with sites that are not aware of PageSpeed. The default level is CoreFilters, to disable use PassThrough.

Enabling, Disabling And Forbidding Specific Filters

The EnableFilters configuration file directive allows specification of one or more filters by name, separated by commas. You can use any number of EnableFilters directives, each of which can contain multiple filter names separated by commas. For example:

pagespeed RewriteLevel PassThrough pagespeed EnableFilters combine_css,extend_cache,rewrite_images pagespeed EnableFilters rewrite_css,rewrite_javascript

To turn off specific filters in the core set, specify:

pagespeed DisableFilters filtera,filterb

For example, if you want to use the core set of filters, but specifically disable rewrite_images and combine_css, you can use:

pagespeed DisableFilters rewrite_images,combine_css

To turn off specific filters and forbid them from being turned on by query parameters, request headers or in location-specific configuration , specify (for example):

pagespeed ForbidFilters rewrite_css,rewrite_javascript

You can use any number of the DisableFilters and/or ForbidFilters directives, each of which can contain multiple filter names separated by commas.

Forbidding All Disabled Filters

You can enable filters for a specific request using either query parameters or request headers, and you can enable filters in sub-directories using the EnableFilters directive if the server module supports configuring that.

In both cases you can enable filters that are disabled or not explicitly enabled in the configuration file, however there are situations where this is undesirable, such as when a filter has been expressly disabled because it breaks a page, or because a filter imposes too great a load on the server.

All disabled filters can be forced off with:

pagespeed ForbidAllDisabledFilters true

Note that in this context disabled filters means all filters that are not enabled by the RewriteLevel or EnableFilters directives.

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

Checking Which Filters Are Enabled

If you want to see exactly which filters are enabled on a virtual host, you can do so by going to that host's admin or statistics page.

Tuning the Filters

Once the rewriters are selected, some of them may also be tuned. These parameters control the inlining and outlining thresholds of various resources.

CssFlattenMaxBytes 102400 (was 2048 prior to PageSpeed 1.9.32.1) CssImageInlineMaxBytes 0 CssInlineMaxBytes 2048 CssOutlineMinBytes 3000 ImageInlineMaxBytes 3072 ImageLimitOptimizedPercent 100 ImageLimitResizeAreaPercent 100 ImageRecompressionQuality 85 ImageResolutionLimitBytes 32000000 JpegRecompressionQuality -1 JpegRecompressionQualityForSmallScreens 70 JpegNumProgressiveScans -1 JpegNumProgressiveScansForSmallScreens -1 WebpRecompressionQuality 80 WebpRecompressionQualityForSmallScreens 70 JsInlineMaxBytes 2048 JsOutlineMinBytes 3000 MaxInlinedPreviewImagesIndex -1 MinImageSizeLowResolutionBytes 3072 RetainComment "[WILDCARD PATTERN]" RewriteRandomDropPercentage 0

Note: The default settings are reasonable and intuitive, but as of this writing (December 2011) have not been experimentally tuned.

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

Unsupported Filters

The PageSpeed code base contains a number of additional filters whose use is unsupported. Some of these are experimental; note that using experimental filters is likely to result in crashes or site breakage. Others are used for debugging specific problems with PageSpeed:

Debugging filter name Brief Description
add_base_tag Adds a <base> element to the beginning of the <head> that reflects the base url PageSpeed is using to resolve relative url references in the page.
debug Adds comments to the page describing actions by certain filters, and attempts to serve JavaScript injected by PageSpeed in source form rather than compiled and minified.
deterministic_js Attempts to provide deterministic JavaScript behavior on each page, for example by replacing the timer and random number generator with functions that return the same sequence of values on every page load.
strip_scripts Removes all script tags from the document.