Skip to main content

filter · Image filters

Deduplicate inlined images (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

ModPagespeedEnableFilters dedup_inlined_images

nginx

pagespeed EnableFilters dedup_inlined_images;

IIS (pagespeed.config)

pagespeed EnableFilters dedup_inlined_images
ParameterDefaultDescription
ImageInlineMaxBytes3072Maximum image size in bytes to inline as a data: URI

Scoping, ForbidFilters and the thresholds filters read: Choosing filters .

Live example

Replaces repeated inlined images with a reference to the first copy.

Measured on the demo page, original against optimized:

  • HTML size

    982 B → 901 B −8%

See the before and after, with the source diff →

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.

This page is drawn from the dedup_inlined_images entry on Image filters. Every filter in one table: PageSpeed filters.

Search