# Filter selection

Choose which mod_pagespeed 2.1 filters run: RewriteLevel presets, the CoreFilters default, EnableFilters, DisableFilters, ForbidFilters and thresholds.

Canonical URL: https://modpagespeed.com/docs/filter-selection/

mod_pagespeed 2.1 applies a set of filters to optimize your pages. You control which filters run through the `RewriteLevel` directive and per-filter enable/disable directives.

For what each filter does, see the [PageSpeed filters](https://modpagespeed.com/docs/filters/) table. This page covers how to select them.

## RewriteLevel

The `RewriteLevel` directive sets the baseline set of filters. Three levels are available:

### CoreFilters (default)

A production-safe set of filters enabled by default. This level balances optimization impact with broad compatibility. Most deployments should start here and add or remove individual filters as needed.

<!-- platform: nginx -->

**nginx**

```nginx
pagespeed RewriteLevel CoreFilters;
```

<!-- platform: apache -->

**Apache**

```apache
ModPagespeedRewriteLevel CoreFilters
```

<!-- platform: iis -->

**IIS**

```text
pagespeed RewriteLevel CoreFilters
```

### PassThrough

No filters are enabled by default. Use this level when you want full control over exactly which filters run. You then enable individual filters with `EnableFilters`.

<!-- platform: nginx -->

**nginx**

```nginx
pagespeed RewriteLevel PassThrough;
```

<!-- platform: apache -->

**Apache**

```apache
ModPagespeedRewriteLevel PassThrough
```

<!-- platform: iis -->

**IIS**

```text
pagespeed RewriteLevel PassThrough
```

### OptimizeForBandwidth

Optimizes resources in place without altering HTML structure. Images are recompressed, CSS and JavaScript are minified, but no URLs are rewritten and no HTML is changed. This level is safe for environments where URL stability is critical.

<!-- platform: nginx -->

**nginx**

```nginx
pagespeed RewriteLevel OptimizeForBandwidth;
```

<!-- platform: apache -->

**Apache**

```apache
ModPagespeedRewriteLevel OptimizeForBandwidth
```

<!-- platform: iis -->

**IIS**

```text
pagespeed RewriteLevel OptimizeForBandwidth
```

## CoreFilters

When `RewriteLevel` is set to `CoreFilters` (the default), the following filters are enabled:

- [`add_head`](https://modpagespeed.com/docs/html-filters/#add_head) — adds a `<head>` element if one is missing
- [`combine_css`](https://modpagespeed.com/docs/css-filters/#combine_css) — combines multiple CSS files into one
- [`combine_javascript`](https://modpagespeed.com/docs/javascript-filters/#combine_javascript) — combines multiple JavaScript files into one
- [`convert_meta_tags`](https://modpagespeed.com/docs/html-filters/#convert_meta_tags) — converts `<meta http-equiv>` tags to response headers
- [`extend_cache`](https://modpagespeed.com/docs/cache-control/#extend_cache) — extends cache lifetime of resources by content-hashing URLs
- [`fallback_rewrite_css_urls`](https://modpagespeed.com/docs/css-filters/#fallback_rewrite_css_urls) — rewrites URLs in CSS even when CSS parsing fails
- [`flatten_css_imports`](https://modpagespeed.com/docs/css-filters/#flatten_css_imports) — inlines `@import` rules in CSS
- [`inline_css`](https://modpagespeed.com/docs/css-filters/#inline_css) — inlines small CSS files into HTML
- [`inline_import_to_link`](https://modpagespeed.com/docs/css-filters/#inline_import_to_link) — converts CSS `@import` to `<link>` tags
- [`inline_javascript`](https://modpagespeed.com/docs/javascript-filters/#inline_javascript) — inlines small JavaScript files into HTML
- [`rewrite_css`](https://modpagespeed.com/docs/css-filters/#rewrite_css) — minifies CSS
- [`rewrite_images`](https://modpagespeed.com/docs/image-filters/#rewrite_images) — recompresses and resizes images
- [`rewrite_javascript`](https://modpagespeed.com/docs/javascript-filters/#rewrite_javascript) — minifies JavaScript
- [`rewrite_style_attributes_with_url`](https://modpagespeed.com/docs/css-filters/#rewrite_style_attributes) — rewrites URLs in `style` attributes

## Enabling and disabling filters

### EnableFilters

Adds filters on top of those already active from the RewriteLevel. Accepts a comma-separated list of filter names.

<!-- platform: nginx -->

**nginx**

```nginx
pagespeed EnableFilters collapse_whitespace,remove_comments;
```

<!-- platform: apache -->

**Apache**

```apache
ModPagespeedEnableFilters collapse_whitespace,remove_comments
```

<!-- platform: iis -->

**IIS**

```text
pagespeed EnableFilters collapse_whitespace,remove_comments
```

### DisableFilters

Removes filters from the active set. Use this to turn off specific CoreFilters you do not want.

<!-- platform: nginx -->

**nginx**

```nginx
pagespeed DisableFilters combine_css,combine_javascript;
```

<!-- platform: apache -->

**Apache**

```apache
ModPagespeedDisableFilters combine_css,combine_javascript
```

<!-- platform: iis -->

**IIS**

```text
pagespeed DisableFilters combine_css,combine_javascript
```

### ForbidFilters

Blocks filters from being enabled by any means, including query parameters and `.htaccess` overrides. Use this to lock down your configuration in multi-tenant or shared-hosting environments.

<!-- platform: nginx -->

**nginx**

```nginx
pagespeed ForbidFilters inline_javascript,inline_css;
```

<!-- platform: apache -->

**Apache**

```apache
ModPagespeedForbidFilters inline_javascript,inline_css
```

<!-- platform: iis -->

**IIS**

```text
pagespeed ForbidFilters inline_javascript,inline_css
```

### ForbidAllDisabledFilters

Automatically forbids every filter that is not currently enabled. This prevents users from enabling additional filters via query parameters or `.htaccess`.

<!-- platform: nginx -->

**nginx**

```nginx
pagespeed ForbidAllDisabledFilters on;
```

<!-- platform: apache -->

**Apache**

```apache
ModPagespeedForbidAllDisabledFilters on
```

<!-- platform: iis -->

**IIS**

```text
pagespeed ForbidAllDisabledFilters on
```

## Checking your filter configuration

Open the admin page at `/pagespeed_admin/config` in your browser to see the full list of active filters and their current settings. This page reflects the running configuration after all directives are applied.

## Tuning parameters

Several directives control size thresholds and quality levels for filter behavior. The table below lists commonly adjusted parameters with their defaults.

| Parameter                   | Default | Description                                                                                |
| --------------------------- | ------- | ------------------------------------------------------------------------------------------ |
| `CssInlineMaxBytes`         | 2048    | Maximum size (bytes) of a CSS file to inline into HTML                                     |
| `JsInlineMaxBytes`          | 2048    | Maximum size (bytes) of a JavaScript file to inline into HTML                              |
| `ImageInlineMaxBytes`       | 3072    | Maximum size (bytes) of an image to inline as a data URI                                   |
| `ImageRecompressionQuality` | 85      | Quality level (-1 to 100; -1 uses the source image's quality) for recompressed JPEG images |
| `CssFlattenMaxBytes`        | 1024000 | Maximum size (bytes) of CSS after flattening `@import` rules                               |

Since v1.15.0+r18, out-of-range values for bounded parameters fail configuration load instead of being silently clamped, so check ranges when tuning.

Set these in your server configuration:

<!-- platform: nginx -->

**nginx**

```nginx
pagespeed CssInlineMaxBytes 4096;
pagespeed ImageRecompressionQuality 75;
```

<!-- platform: apache -->

**Apache**

```apache
ModPagespeedCssInlineMaxBytes 4096
ModPagespeedImageRecompressionQuality 75
```

<!-- platform: iis -->

**IIS**

```text
pagespeed CssInlineMaxBytes 4096
pagespeed ImageRecompressionQuality 75
```

## URL preservation

By default, mod_pagespeed 2.1 rewrites resource URLs to include content hashes for cache extension. If you use a CDN or other infrastructure that requires stable, unchanged URLs, set the URL-preservation options for the affected resource types:

<!-- platform: nginx -->

**nginx**

```nginx
pagespeed ImagePreserveURLs on;
pagespeed CssPreserveURLs on;
pagespeed JsPreserveURLs on;
```

<!-- platform: apache -->

**Apache**

```apache
ModPagespeedImagePreserveURLs on
ModPagespeedCssPreserveURLs on
ModPagespeedJsPreserveURLs on
```

<!-- platform: iis -->

**IIS**

```text
pagespeed ImagePreserveURLs on
pagespeed CssPreserveURLs on
pagespeed JsPreserveURLs on
```

With URL preservation enabled, mod_pagespeed still optimizes the resource content (recompression, minification) but serves it at the original URL. The optimized variant is loaded on the first request and served on subsequent requests via the in-place resource optimization flow.

## Links

- [PageSpeed filters](https://modpagespeed.com/docs/filters/) — every filter, what it does and which level enables it
- [Configuration](https://modpagespeed.com/docs/configuration/) — general configuration directives
