Skip to main content

PageSpeed filters

Documentation

A PageSpeed filter is one named optimization that mod_pagespeed, the in-process module for Apache, nginx and IIS, applies to a page or a resource as the server serves it: recompress an image, minify and combine CSS and JavaScript, inline the critical CSS, extend a cache lifetime. The table lists every filter mod_pagespeed 2.1 accepts — 94 filters and 4 compound names that expand to several — generated from the module source at v2.2.0, so it is the list the shipped module knows. Each name links to the entry that explains what the filter changes, when to use it and what can go wrong.

Looking for the Google PageSpeed Insights score at pagespeed.web.dev? That is Google’s online scoring tool. This page documents the optimization filters that do the work, not the score. To measure a URL yourself, use Analyze.

How to enable a filter

RewriteLevel picks the baseline set: CoreFilters (the default) enables the 29 filters marked Core, OptimizeForBandwidth enables the 13 marked OFB and leaves URLs unchanged, PassThrough enables none. Add or remove individual filters by name:

pagespeed EnableFilters rewrite_images,lazyload_images;   # nginx
pagespeed DisableFilters convert_jpeg_to_webp;
ModPagespeedEnableFilters rewrite_images,lazyload_images   # Apache
pagespeed EnableFilters rewrite_images,lazyload_images     # IIS (pagespeed.config)

Scoping per virtual host and location, ForbidFilters and the thresholds each filter reads are on Choosing filters. The optimizer worker behind the Docker image runs a different pipeline, configured by flags rather than this list: see Worker and reverse-proxy configuration.

The full list of PageSpeed filters

Alphabetical. Core and OFB: enabled by RewriteLevel CoreFilters / OptimizeForBandwidth (Part: a compound name whose members are only partly in the set). Risk: the rating from the group page; Dangerous marks the module’s own dangerous set, which AllFilters never enables, and Deprecated a name that is accepted but does nothing. Example opens the live before/after demo where the gallery has one.

Filter What it does Category Core OFB Risk Example
add_base_tag (section) Adds a <base href> for the page URL so relative URLs resolve against it HTML — — —
add_head (section) Adds <head> element if missing HTML Yes — Generally safe
add_ids (section) Adds id attributes to elements that have none, for beacon-driven filters HTML — — —
add_instrumentation (section) Injects JavaScript to measure page load time HTML — — Test first demo
cache_partial_html (section) Deprecated no-op: accepted for compatibility, does nothing HTML — — Dangerous
canonicalize_javascript_libraries (section) Replaces recognized JavaScript libraries with a canonical CDN URL Targets the Google Hosted Libraries CDN; listed as deprecated in these docs. JavaScript — — Dangerous demo
collapse_whitespace Removes excess whitespace from HTML HTML — — Generally safe demo
combine_css Combines multiple CSS files into one CSS Yes — Generally safe demo
combine_heads Merges multiple <head> elements HTML — — Generally safe demo
combine_javascript Combines multiple JS files into one JavaScript Yes — Generally safe demo
compute_critical_css (section) Computes critical CSS in the background (experimental; prefer prioritize_critical_css) CSS — — —
compute_statistics (section) Computes HTML statistics for the admin console HTML — — —
convert_gif_to_png Converts GIF to PNG Image Yes Yes Generally safe
convert_jpeg_to_avif (section) Converts photographic JPEG to AVIF for capable browsers Image — — Test first demo
convert_jpeg_to_progressive (section) Converts large JPEGs to progressive format Image Yes Yes Generally safe
convert_jpeg_to_webp Converts JPEG to WebP for capable browsers Image Yes Yes Generally safe
convert_meta_tags (section) Adds HTTP headers from <meta http-equiv> tags HTML Yes — Generally safe
convert_png_to_jpeg Converts PNG to JPEG when no transparency Image Yes Yes Generally safe
convert_to_avif_animated (section) Converts animated images to AVIF Image — — Test first demo
convert_to_avif_lossless (section) Converts PNG/GIF to lossless AVIF Image — — Test first
convert_to_webp_animated (section) Converts animated GIF to WebP Image — — Test first
convert_to_webp_lossless (section) Converts PNG/GIF to lossless WebP Image Yes — Test first
debug (section) Annotates the page with comments explaining rewriting decisions HTML — — —
decode_rewritten_urls (section) Turns .pagespeed. resource URLs back into their original URLs HTML — — —
dedup_inlined_images Replaces repeated inlined images with JS reference Image — — Generally safe demo
defer_iframe (section) Deprecated no-op: iframe deferral is part of defer_javascript HTML — — Dangerous
defer_javascript Defers JS execution until after page load JavaScript — — Test first demo
deterministic_js (section) Makes Date and Math.random deterministic, for measurement runs JavaScript — — Dangerous
disable_javascript (section) Disables scripts by placing them inside noscript tags JavaScript — — Dangerous
div_structure (section) Deprecated no-op: accepted for compatibility, does nothing HTML — — Dangerous
elide_attributes (section) Removes default-value HTML attributes HTML — — Generally safe demo
experiment_collect_mob_image_info (section) Experiment: collects image information for mobilization Image — — Dangerous
experiment_http2 (section) Experiment: HTTP/2-specific features in development HTML — — —
explicit_close_tags (section) Deprecated no-op: accepted for compatibility, does nothing HTML — — Dangerous
extend_cache = extend_cache_css, extend_cache_images, extend_cache_scripts Content-hashed URLs with a 1-year browser cache for CSS, images and scripts Caching Yes — Generally safe demo
extend_cache_css (section) Content-hashed URLs with a 1-year browser cache for stylesheets CSS Yes — Generally safe
extend_cache_images (section) Content-hashed URLs with a 1-year browser cache for images Image Yes — Generally safe
extend_cache_pdfs (section) Cache extension for PDF links Caching — — Generally safe demo
extend_cache_scripts (section) Content-hashed URLs with a 1-year browser cache for scripts JavaScript Yes — Generally safe
fallback_rewrite_css_urls (section) Rewrites resource URLs in unparseable CSS CSS Yes — Generally safe demo
fix_reflows (section) Experimental reflow fix for deferred JavaScript HTML — — Dangerous
flatten_css_imports (section) Inlines CSS @import rules CSS Yes — Generally safe demo
flush_subresources (section) Deprecated no-op: accepted for compatibility, does nothing HTML — — Dangerous
hint_preload_subresources (section) Adds Link: rel=preload headers HTML — — Generally safe demo
in_place_optimize_for_browser (section) Browser-specific in-place optimization Retired: the name is still accepted (with a warning) but has no effect, because in-place optimization no longer varies its output by browser. Image — — —
include_js_source_maps (section) Preserves JavaScript source maps JavaScript — — Generally safe
inline_css Inlines small external CSS into HTML CSS Yes — Generally safe demo
inline_google_font_css (section) Inlines Google Fonts CSS CSS — — Generally safe demo
inline_images Inlines small images as data: URIs Image Yes — Generally safe demo
inline_javascript Inlines small external JS into HTML JavaScript Yes — Generally safe demo
inline_preview_images Inserts low-quality image placeholders Image — — Test first demo
insert_dns_prefetch Adds <link rel=dns-prefetch> for third-party domains HTML — — Generally safe demo
insert_ga (section) Inserts the Google Analytics snippet for AnalyticsID (retired ga.js) Inserts the retired ga.js Google Analytics snippet. HTML — — Deprecated
insert_image_dimensions Adds width and height attributes to <img> tags Image — — Generally safe
insert_img_dimensions (section) alternate spelling of insert_image_dimensions Alternate spelling of insert_image_dimensions Image — — Generally safe
insert_speculation_rules Injects a same-origin prefetch speculation-rules script HTML — — Test first demo
jpeg_subsampling (section) Reduces chroma sampling to 4:2:0 Image Yes Yes Generally safe
lazyload_images Defers offscreen image loading Native mode (the default) is generally safe; test `js` mode first. Image — — Generally safe demo
left_trim_urls (section) alternate spelling of trim_urls Alternate spelling of trim_urls HTML — — Generally safe
local_storage_cache Caches inlined resources in localStorage Caching — — Experimental demo
make_google_analytics_async (section) Deprecated no-op: targeted the retired ga.js Targets the retired ga.js. JavaScript — — Dangerous
make_show_ads_async (section) Converts showads.js use to async adsbygoogle.js Targets the deprecated AdSense show_ads.js. JavaScript — — Deprecated demo
mobilize (section) Experimental page mobilization (dangerous set) HTML — — Dangerous
mobilize_precompute (section) Deprecated no-op: accepted for compatibility, does nothing HTML — — Dangerous
move_css_above_scripts Moves CSS <link> above <script> tags CSS — — Generally safe demo
move_css_to_head Moves CSS <link> into <head> CSS — — Generally safe demo
outline_css Externalizes large inline CSS blocks CSS — — Experimental demo
outline_javascript Externalizes large inline JS blocks JavaScript — — Experimental demo
pedantic (section) Adds type attributes for HTML4 validation HTML — — Generally safe demo
prioritize_critical_css Inlines the CSS a page uses, loads the rest async CSS — — Test first demo
prioritize_critical_images Sets fetchpriority=high on the LCP image Image — — Test first demo
recompress_avif (section) AVIF-specific recompression Image — — Test first
recompress_images = convert_gif_to_png, convert_jpeg_to_progressive, convert_jpeg_to_webp, convert_png_to_jpeg, jpeg_subsampling, recompress_jpeg, recompress_png, recompress_webp, strip_image_color_profile, strip_image_meta_data Recompresses and converts images in every format (enables the sub-filters) Image Yes Yes Generally safe
recompress_jpeg JPEG-specific recompression Image Yes Yes Generally safe
recompress_png PNG-specific recompression Image Yes Yes Generally safe
recompress_webp WebP-specific recompression Image Yes Yes Generally safe
remove_comments Strips HTML comments HTML — — Generally safe demo
remove_quotes (section) Removes unnecessary attribute quotes HTML — — Generally safe demo
resize_images Resizes images to match <img> dimensions Image Yes — Generally safe
resize_mobile_images (section) Smaller placeholders for mobile Image — — Test first demo
resize_rendered_image_dimensions (section) Resizes to rendered dimensions Image — — Test first demo
responsive_images Generates srcset for multiple resolutions Image — — Test first demo
responsive_images_zoom (section) Adds the zoom-aware script for responsive_images srcsets Image — — —
rewrite_css Minifies CSS, rewrites embedded URLs CSS Yes Yes Generally safe demo
rewrite_domains (section) Applies domain mappings to original resources Caching — — Test first
rewrite_images = convert_gif_to_png, convert_jpeg_to_progressive, convert_jpeg_to_webp, convert_png_to_jpeg, convert_to_webp_lossless, inline_images, jpeg_subsampling, recompress_jpeg, recompress_png, recompress_webp, resize_images, strip_image_color_profile, strip_image_meta_data Master image optimization: recompress, convert, resize and inline (enables the sub-filters) Image Yes Part Generally safe demo
rewrite_javascript = rewrite_javascript_external, rewrite_javascript_inline Minifies external and inline JavaScript (enables both sub-filters) JavaScript Yes Yes Generally safe demo
rewrite_javascript_external Minifies external JavaScript files JavaScript Yes Yes Generally safe
rewrite_javascript_inline Minifies inline JavaScript JavaScript Yes Yes Generally safe
rewrite_style_attributes (section) Applies CSS rewriting to inline style attributes CSS — — Generally safe demo
rewrite_style_attributes_with_url (section) Same, only for styles containing url() CSS Yes — Generally safe demo
split_html (section) Deprecated no-op: accepted for compatibility, does nothing HTML — — Dangerous
split_html_helper (section) Deprecated no-op: accepted for compatibility, does nothing HTML — — Dangerous
sprite_images Combines CSS background images into sprites Image — — Test first demo
strip_image_color_profile (section) Removes ICC color profiles Image Yes Yes Generally safe
strip_image_meta_data (section) Removes EXIF and other metadata Image Yes Yes Generally safe
strip_scripts (section) Removes all scripts from the page, for measurement runs JavaScript — — Dangerous
trim_urls Shortens URLs relative to base URL HTML — — Generally safe demo

94 filters, 4 compound names, 29 in CoreFilters, 13 in OptimizeForBandwidth, 16 in the dangerous set, 9 deprecated. Generated from the module source at v2.2.0.

Frequently asked questions

What is a PageSpeed filter?
A filter is one named optimization that mod_pagespeed applies to a page or a resource as the web server serves it: recompress an image, minify or combine a stylesheet, inline a small script, extend a cache lifetime. Filters are enabled by name with EnableFilters, or as a set with RewriteLevel.
Which filters are on by default?
RewriteLevel CoreFilters, the default, enables the 29 filters marked Core in the table. OptimizeForBandwidth enables the 13 filters marked OFB and keeps URLs unchanged. PassThrough enables none, and AllFilters enables every filter outside the dangerous set.
How do I enable or disable a filter?
Add it to EnableFilters or DisableFilters: pagespeed EnableFilters rewrite_images,lazyload_images; on nginx, ModPagespeedEnableFilters rewrite_images,lazyload_images on Apache, and the nginx form without the semicolon in pagespeed.config on IIS. A filter can also be forbidden for a whole server with ForbidFilters.
Does the Docker image use these filters?
No. The native module for Apache, nginx and IIS uses this filter list. The optimizer worker behind the Docker image and the Helm chart runs its own pipeline (image transcoding, critical CSS, caching) configured by command-line flags; see the worker and reverse-proxy configuration page.

Search