# Deduplicate inlined images (dedup_inlined_images)

Replaces repeated inlined images with JS reference. The dedup_inlined_images filter: what it does, its risks and the Apache, nginx and IIS directives.

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

- Category: Image
- CoreFilters: No
- OptimizeForBandwidth: No
- Risk: Generally safe

**`dedup_inlined_images`** replaces repeated inline `data:` URIs on the same page with JavaScript references to the first occurrence, reducing HTML size.

## How it works

`dedup_inlined_images` shrinks pages that repeat the same inlined image. When two or more references have become identical `data:` URIs, the first occurrence keeps its bytes and gets an `id`; every later occurrence of the same data URI loses its `src` and instead carries a one-line inline script that copies the first image's `src` back onto the element at run time. There is a floor below which dedup does not pay: a data URI must be longer than 185 bytes, roughly the size of the restoring snippet, or it is left as it is. The filter needs JavaScript, so it is disabled for user agents that cannot lazy-load images and for XMLHttpRequests, and it stands down inside `<noscript>` or when the page's Content-Security-Policy forbids inline scripts. The `num_dedup_inlined_images_candidates_found` and `num_dedup_inlined_images_candidates_replaced` statistics in the admin console show how much it found and how much it replaced.

## When to use it

- Not in CoreFilters: it runs only when you enable it by name.
- Risk rating on these docs: **Generally safe**.

## Risks

- Inlining increases HTML size. Inlined images are not cached separately by the browser. Set `ImageInlineMaxBytes` conservatively.

## Configuration

Enable it in the module configuration, at server, virtual-host or location scope:

**Apache**

```apache
ModPagespeedEnableFilters dedup_inlined_images
```

**nginx**

```nginx
pagespeed EnableFilters dedup_inlined_images;
```

**IIS (pagespeed.config)**

```text
pagespeed EnableFilters dedup_inlined_images
```

| Parameter             | Default | Description                                          |
| --------------------- | ------- | ---------------------------------------------------- |
| `ImageInlineMaxBytes` | 3072    | Maximum image size in bytes to inline as a data: URI |

Scoping, `ForbidFilters` and the thresholds filters read: [Choosing filters](https://modpagespeed.com/docs/filter-selection/).

## Live example

See the before and after, with the source diff: [dedup_inlined_images example](https://modpagespeed.com/examples/dedup_inlined_images/).

## Frequently asked questions

**What does the dedup_inlined_images filter do?**

`dedup_inlined_images` replaces repeated inline `data:` URIs on the same page with JavaScript references to the first occurrence, reducing HTML size.

**Is dedup_inlined_images enabled by default?**

No. `dedup_inlined_images` is not in CoreFilters, the default RewriteLevel; it runs only when you enable it by name with `EnableFilters`.

**How do I enable dedup_inlined_images on Apache and nginx?**

Add `ModPagespeedEnableFilters dedup_inlined_images` on Apache or `pagespeed EnableFilters dedup_inlined_images;` on nginx. On IIS, add `pagespeed EnableFilters dedup_inlined_images` to pagespeed.config.

## Related filters

- [`inline_images`](https://modpagespeed.com/docs/filters/inline_images/): Inline images
- [`inline_preview_images`](https://modpagespeed.com/docs/filters/inline_preview_images/): Inline preview images
- [`resize_mobile_images`](https://modpagespeed.com/docs/filters/resize_mobile_images/): Resize images for mobile
- [`convert_gif_to_png`](https://modpagespeed.com/docs/filters/convert_gif_to_png/): Convert GIF to PNG
- [`convert_jpeg_to_avif`](https://modpagespeed.com/docs/filters/convert_jpeg_to_avif/): Convert JPEG to AVIF
- [`convert_jpeg_to_progressive`](https://modpagespeed.com/docs/filters/convert_jpeg_to_progressive/): Progressive JPEG
- [`convert_jpeg_to_webp`](https://modpagespeed.com/docs/filters/convert_jpeg_to_webp/): Convert JPEG to WebP
- [`convert_png_to_jpeg`](https://modpagespeed.com/docs/filters/convert_png_to_jpeg/): Convert PNG to JPEG

This page is drawn from the [dedup_inlined_images entry on Image filters](https://modpagespeed.com/docs/image-filters/#dedup_inlined_images). Every filter in one table: [PageSpeed filters](https://modpagespeed.com/docs/filters/).
