# PageSpeed filters

The image, CSS, JavaScript, HTML, and caching filters, what each one does, and which run by default.

Canonical URL: https://modpagespeed.com/docs/filters/

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. The tables list every filter mod_pagespeed 2.1 accepts: 94 filters and 4 compound names that expand to several. Core means the filter is in CoreFilters, the default RewriteLevel. OFB means it is in OptimizeForBandwidth. Each name links to the entry that explains what the filter changes, when to use it and what can go wrong.

## Image filters

| Filter | Core | OFB | Risk | What it does |
| --- | --- | --- | --- | --- |
| [`convert_gif_to_png`](https://modpagespeed.com/docs/filters/convert_gif_to_png/) | Yes | Yes | Generally safe | Converts GIF to PNG |
| [`convert_jpeg_to_avif`](https://modpagespeed.com/docs/image-filters/#convert_jpeg_to_avif) | - | - | Test first | Converts photographic JPEG to AVIF for capable browsers |
| [`convert_jpeg_to_progressive`](https://modpagespeed.com/docs/image-filters/#convert_jpeg_to_progressive) | Yes | Yes | Generally safe | Converts large JPEGs to progressive format |
| [`convert_jpeg_to_webp`](https://modpagespeed.com/docs/filters/convert_jpeg_to_webp/) | Yes | Yes | Generally safe | Converts JPEG to WebP for capable browsers |
| [`convert_png_to_jpeg`](https://modpagespeed.com/docs/filters/convert_png_to_jpeg/) | Yes | Yes | Generally safe | Converts PNG to JPEG when no transparency |
| [`convert_to_avif_animated`](https://modpagespeed.com/docs/image-filters/#convert_to_avif_animated) | - | - | Test first | Converts animated images to AVIF |
| [`convert_to_avif_lossless`](https://modpagespeed.com/docs/image-filters/#convert_to_avif_lossless) | - | - | Test first | Converts PNG/GIF to lossless AVIF |
| [`convert_to_webp_animated`](https://modpagespeed.com/docs/image-filters/#convert_to_webp_animated) | - | - | Test first | Converts animated GIF to WebP |
| [`convert_to_webp_lossless`](https://modpagespeed.com/docs/image-filters/#convert_to_webp_lossless) | Yes | - | Test first | Converts PNG/GIF to lossless WebP |
| [`dedup_inlined_images`](https://modpagespeed.com/docs/filters/dedup_inlined_images/) | - | - | Generally safe | Replaces repeated inlined images with JS reference |
| [`experiment_collect_mob_image_info`](https://modpagespeed.com/docs/image-filters/#experiment_collect_mob_image_info) | - | - | Dangerous | Experiment: collects image information for mobilization |
| [`extend_cache_images`](https://modpagespeed.com/docs/image-filters/#extend_cache_images) | Yes | - | Generally safe | Content-hashed URLs with a 1-year browser cache for images |
| [`in_place_optimize_for_browser`](https://modpagespeed.com/docs/image-filters/#in_place_optimize_for_browser) | - | - | - | Browser-specific in-place optimization |
| [`inline_images`](https://modpagespeed.com/docs/filters/inline_images/) | Yes | - | Generally safe | Inlines small images as data: URIs |
| [`inline_preview_images`](https://modpagespeed.com/docs/filters/inline_preview_images/) | - | - | Test first | Inserts low-quality image placeholders |
| [`insert_image_dimensions`](https://modpagespeed.com/docs/filters/insert_image_dimensions/) | - | - | Generally safe | Adds width and height attributes to `<img>` tags |
| [`insert_img_dimensions`](https://modpagespeed.com/docs/image-filters/#insert_img_dimensions) | - | - | Generally safe | Alternate spelling of insert_image_dimensions |
| [`jpeg_subsampling`](https://modpagespeed.com/docs/image-filters/#jpeg_subsampling) | Yes | Yes | Generally safe | Reduces chroma sampling to 4:2:0 |
| [`lazyload_images`](https://modpagespeed.com/docs/filters/lazyload_images/) | - | - | Generally safe | Defers offscreen image loading |
| [`prioritize_critical_images`](https://modpagespeed.com/docs/filters/prioritize_critical_images/) | - | - | Test first | Sets fetchpriority=high on the LCP image |
| [`recompress_avif`](https://modpagespeed.com/docs/image-filters/#recompress_avif) | - | - | Test first | AVIF-specific recompression |
| [`recompress_jpeg`](https://modpagespeed.com/docs/filters/recompress_jpeg/) | Yes | Yes | Generally safe | JPEG-specific recompression |
| [`recompress_png`](https://modpagespeed.com/docs/filters/recompress_png/) | Yes | Yes | Generally safe | PNG-specific recompression |
| [`recompress_webp`](https://modpagespeed.com/docs/filters/recompress_webp/) | Yes | Yes | Generally safe | WebP-specific recompression |
| [`resize_images`](https://modpagespeed.com/docs/filters/resize_images/) | Yes | - | Generally safe | Resizes images to match `<img>` dimensions |
| [`resize_mobile_images`](https://modpagespeed.com/docs/image-filters/#resize_mobile_images) | - | - | Test first | Smaller placeholders for mobile |
| [`resize_rendered_image_dimensions`](https://modpagespeed.com/docs/image-filters/#resize_rendered_image_dimensions) | - | - | Test first | Resizes to rendered dimensions |
| [`responsive_images`](https://modpagespeed.com/docs/filters/responsive_images/) | - | - | Test first | Generates srcset for multiple resolutions |
| [`responsive_images_zoom`](https://modpagespeed.com/docs/image-filters/#responsive_images_zoom) | - | - | - | Adds the zoom-aware script for responsive_images srcsets |
| [`sprite_images`](https://modpagespeed.com/docs/filters/sprite_images/) | - | - | Test first | Combines CSS background images into sprites |
| [`strip_image_color_profile`](https://modpagespeed.com/docs/image-filters/#strip_image_color_profile) | Yes | Yes | Generally safe | Removes ICC color profiles |
| [`strip_image_meta_data`](https://modpagespeed.com/docs/image-filters/#strip_image_meta_data) | Yes | Yes | Generally safe | Removes EXIF and other metadata |
| [`recompress_images`](https://modpagespeed.com/docs/filters/recompress_images/) | Yes | Yes | Generally safe | Recompresses and converts images in every format (enables the sub-filters) |
| [`rewrite_images`](https://modpagespeed.com/docs/filters/rewrite_images/) | Yes | Part | Generally safe | Master image optimization: recompress, convert, resize and inline (enables the sub-filters) |

## CSS filters

| Filter | Core | OFB | Risk | What it does |
| --- | --- | --- | --- | --- |
| [`combine_css`](https://modpagespeed.com/docs/filters/combine_css/) | Yes | - | Generally safe | Combines multiple CSS files into one |
| [`compute_critical_css`](https://modpagespeed.com/docs/css-filters/#compute_critical_css) | - | - | - | Computes critical CSS in the background (experimental; prefer prioritize_critical_css) |
| [`extend_cache_css`](https://modpagespeed.com/docs/css-filters/#extend_cache_css) | Yes | - | Generally safe | Content-hashed URLs with a 1-year browser cache for stylesheets |
| [`fallback_rewrite_css_urls`](https://modpagespeed.com/docs/css-filters/#fallback_rewrite_css_urls) | Yes | - | Generally safe | Rewrites resource URLs in unparseable CSS |
| [`flatten_css_imports`](https://modpagespeed.com/docs/css-filters/#flatten_css_imports) | Yes | - | Generally safe | Inlines CSS @import rules |
| [`inline_css`](https://modpagespeed.com/docs/filters/inline_css/) | Yes | - | Generally safe | Inlines small external CSS into HTML |
| [`inline_google_font_css`](https://modpagespeed.com/docs/css-filters/#inline_google_font_css) | - | - | Generally safe | Inlines Google Fonts CSS |
| [`inline_import_to_link`](https://modpagespeed.com/docs/css-filters/#inline_import_to_link) | Yes | - | Generally safe | Converts `<style>`@import`</style>` to `<link>` |
| [`move_css_above_scripts`](https://modpagespeed.com/docs/filters/move_css_above_scripts/) | - | - | Generally safe | Moves CSS `<link>` above `<script>` tags |
| [`move_css_to_head`](https://modpagespeed.com/docs/filters/move_css_to_head/) | - | - | Generally safe | Moves CSS `<link>` into `<head>` |
| [`outline_css`](https://modpagespeed.com/docs/filters/outline_css/) | - | - | Experimental | Externalizes large inline CSS blocks |
| [`prioritize_critical_css`](https://modpagespeed.com/docs/filters/prioritize_critical_css/) | - | - | Test first | Inlines the CSS a page uses, loads the rest async |
| [`rewrite_css`](https://modpagespeed.com/docs/filters/rewrite_css/) | Yes | Yes | Generally safe | Minifies CSS, rewrites embedded URLs |
| [`rewrite_style_attributes`](https://modpagespeed.com/docs/css-filters/#rewrite_style_attributes) | - | - | Generally safe | Applies CSS rewriting to inline style attributes |
| [`rewrite_style_attributes_with_url`](https://modpagespeed.com/docs/css-filters/#rewrite_style_attributes_with_url) | Yes | - | Generally safe | rewrite_style_attributes applies CSS rewriting (minification, URL rewriting) to inline style="" attributes on HTML elements. |

## JavaScript filters

| Filter | Core | OFB | Risk | What it does |
| --- | --- | --- | --- | --- |
| [`canonicalize_javascript_libraries`](https://modpagespeed.com/docs/javascript-filters/#canonicalize_javascript_libraries) | - | - | Dangerous | Replaces recognized JavaScript libraries with a canonical CDN URL |
| [`combine_javascript`](https://modpagespeed.com/docs/filters/combine_javascript/) | Yes | - | Generally safe | Combines multiple JS files into one |
| [`defer_javascript`](https://modpagespeed.com/docs/filters/defer_javascript/) | - | - | Test first | Defers JS execution until after page load |
| [`deterministic_js`](https://modpagespeed.com/docs/javascript-filters/#deterministic_js) | - | - | Dangerous | Makes Date and Math.random deterministic, for measurement runs |
| [`disable_javascript`](https://modpagespeed.com/docs/javascript-filters/#disable_javascript) | - | - | Dangerous | Disables scripts by placing them inside noscript tags |
| [`extend_cache_scripts`](https://modpagespeed.com/docs/javascript-filters/#extend_cache_scripts) | Yes | - | Generally safe | Content-hashed URLs with a 1-year browser cache for scripts |
| [`include_js_source_maps`](https://modpagespeed.com/docs/javascript-filters/#include_js_source_maps) | - | - | Generally safe | Preserves JavaScript source maps |
| [`inline_javascript`](https://modpagespeed.com/docs/filters/inline_javascript/) | Yes | - | Generally safe | Inlines small external JS into HTML |
| [`make_google_analytics_async`](https://modpagespeed.com/docs/javascript-filters/#make_google_analytics_async) | - | - | Dangerous | Deprecated no-op: targeted the retired ga.js |
| [`make_show_ads_async`](https://modpagespeed.com/docs/javascript-filters/#make_show_ads_async) | - | - | Deprecated | Converts showads.js use to async adsbygoogle.js |
| [`outline_javascript`](https://modpagespeed.com/docs/filters/outline_javascript/) | - | - | Experimental | Externalizes large inline JS blocks |
| [`rewrite_javascript_external`](https://modpagespeed.com/docs/filters/rewrite_javascript_external/) | Yes | Yes | Generally safe | Minifies external JavaScript files |
| [`rewrite_javascript_inline`](https://modpagespeed.com/docs/filters/rewrite_javascript_inline/) | Yes | Yes | Generally safe | Minifies inline JavaScript |
| [`strip_scripts`](https://modpagespeed.com/docs/javascript-filters/#strip_scripts) | - | - | Dangerous | Removes all scripts from the page, for measurement runs |
| [`rewrite_javascript`](https://modpagespeed.com/docs/filters/rewrite_javascript/) | Yes | Yes | Generally safe | Minifies external and inline JavaScript (enables both sub-filters) |

## HTML filters

| Filter | Core | OFB | Risk | What it does |
| --- | --- | --- | --- | --- |
| [`add_base_tag`](https://modpagespeed.com/docs/html-filters/#add_base_tag) | - | - | - | Adds a `<base href>` for the page URL so relative URLs resolve against it |
| [`add_head`](https://modpagespeed.com/docs/html-filters/#add_head) | Yes | - | Generally safe | Adds `<head>` element if missing |
| [`add_ids`](https://modpagespeed.com/docs/html-filters/#add_ids) | - | - | - | Adds id attributes to elements that have none, for beacon-driven filters |
| [`add_instrumentation`](https://modpagespeed.com/docs/html-filters/#add_instrumentation) | - | - | Test first | Injects JavaScript to measure page load time |
| [`cache_partial_html`](https://modpagespeed.com/docs/html-filters/#cache_partial_html) | - | - | Dangerous | Deprecated no-op: accepted for compatibility, does nothing |
| [`collapse_whitespace`](https://modpagespeed.com/docs/filters/collapse_whitespace/) | - | - | Generally safe | Removes excess whitespace from HTML |
| [`combine_heads`](https://modpagespeed.com/docs/filters/combine_heads/) | - | - | Generally safe | Merges multiple `<head>` elements |
| [`compute_statistics`](https://modpagespeed.com/docs/html-filters/#compute_statistics) | - | - | - | Computes HTML statistics for the admin console |
| [`convert_meta_tags`](https://modpagespeed.com/docs/html-filters/#convert_meta_tags) | Yes | - | Generally safe | Adds HTTP headers from `<meta http-equiv>` tags |
| [`debug`](https://modpagespeed.com/docs/html-filters/#debug) | - | - | - | Annotates the page with comments explaining rewriting decisions |
| [`decode_rewritten_urls`](https://modpagespeed.com/docs/html-filters/#decode_rewritten_urls) | - | - | - | Turns .pagespeed. resource URLs back into their original URLs |
| [`defer_iframe`](https://modpagespeed.com/docs/html-filters/#defer_iframe) | - | - | Dangerous | Deprecated no-op: iframe deferral is part of defer_javascript |
| [`div_structure`](https://modpagespeed.com/docs/html-filters/#div_structure) | - | - | Dangerous | Deprecated no-op: accepted for compatibility, does nothing |
| [`elide_attributes`](https://modpagespeed.com/docs/html-filters/#elide_attributes) | - | - | Generally safe | Removes default-value HTML attributes |
| [`experiment_http2`](https://modpagespeed.com/docs/html-filters/#experiment_http2) | - | - | - | Experiment: HTTP/2-specific features in development |
| [`explicit_close_tags`](https://modpagespeed.com/docs/html-filters/#explicit_close_tags) | - | - | Dangerous | Deprecated no-op: accepted for compatibility, does nothing |
| [`fix_reflows`](https://modpagespeed.com/docs/html-filters/#fix_reflows) | - | - | Dangerous | Experimental reflow fix for deferred JavaScript |
| [`flush_subresources`](https://modpagespeed.com/docs/html-filters/#flush_subresources) | - | - | Dangerous | Deprecated no-op: accepted for compatibility, does nothing |
| [`hint_preload_subresources`](https://modpagespeed.com/docs/html-filters/#hint_preload_subresources) | - | - | Generally safe | Adds Link: rel=preload headers |
| [`insert_amp_link`](https://modpagespeed.com/docs/html-filters/#insert_amp_link) | - | - | - | Adds a `<link rel=amphtml>` from AmpLinkPattern |
| [`insert_dns_prefetch`](https://modpagespeed.com/docs/filters/insert_dns_prefetch/) | - | - | Generally safe | Adds `<link rel=dns-prefetch>` for third-party domains |
| [`insert_ga`](https://modpagespeed.com/docs/html-filters/#insert_ga) | - | - | Deprecated | Inserts the Google Analytics snippet for AnalyticsID (retired ga.js) |
| [`insert_speculation_rules`](https://modpagespeed.com/docs/filters/insert_speculation_rules/) | - | - | Test first | Injects a same-origin prefetch speculation-rules script |
| [`left_trim_urls`](https://modpagespeed.com/docs/html-filters/#left_trim_urls) | - | - | Generally safe | Alternate spelling of trim_urls |
| [`mobilize`](https://modpagespeed.com/docs/html-filters/#mobilize) | - | - | Dangerous | Experimental page mobilization (dangerous set) |
| [`mobilize_precompute`](https://modpagespeed.com/docs/html-filters/#mobilize_precompute) | - | - | Dangerous | Deprecated no-op: accepted for compatibility, does nothing |
| [`pedantic`](https://modpagespeed.com/docs/html-filters/#pedantic) | - | - | Generally safe | Adds type attributes for HTML4 validation |
| [`remove_comments`](https://modpagespeed.com/docs/filters/remove_comments/) | - | - | Generally safe | Strips HTML comments |
| [`remove_quotes`](https://modpagespeed.com/docs/html-filters/#remove_quotes) | - | - | Generally safe | Removes unnecessary attribute quotes |
| [`split_html`](https://modpagespeed.com/docs/html-filters/#split_html) | - | - | Dangerous | Deprecated no-op: accepted for compatibility, does nothing |
| [`split_html_helper`](https://modpagespeed.com/docs/html-filters/#split_html_helper) | - | - | Dangerous | Deprecated no-op: accepted for compatibility, does nothing |
| [`trim_urls`](https://modpagespeed.com/docs/filters/trim_urls/) | - | - | Generally safe | Shortens URLs relative to base URL |

## Caching and URL filters

| Filter | Core | OFB | Risk | What it does |
| --- | --- | --- | --- | --- |
| [`extend_cache_pdfs`](https://modpagespeed.com/docs/cache-control/#extend_cache_pdfs) | - | - | Generally safe | Cache extension for PDF links |
| [`local_storage_cache`](https://modpagespeed.com/docs/filters/local_storage_cache/) | - | - | Experimental | Caches inlined resources in localStorage |
| [`rewrite_domains`](https://modpagespeed.com/docs/cache-control/#rewrite_domains) | - | - | Test first | Applies domain mappings to original resources |
| [`extend_cache`](https://modpagespeed.com/docs/filters/extend_cache/) | Yes | - | Generally safe | Content-hashed URLs with a 1-year browser cache for CSS, images and scripts |
