Skip to main content

filter · Image filters

Recompress JPEG (recompress_jpeg)

Category:
Image
CoreFilters:
Yes
OptimizeForBandwidth:
Yes
Risk:
Generally safe

recompress_jpeg re-encodes JPEG images that reach it. It runs after the conversion candidates: a JPEG that was not converted to WebP or AVIF for this request is re-encoded at JpegRecompressionQuality, which defaults to -1, meaning it follows ImageRecompressionQuality (default 85). Only when ImageRecompressionQuality is itself -1 does the module keep the source file’s own quality.

How it works

The recompression filters reduce image file size by re-encoding images at an optimal quality level. They preserve visual quality while removing encoding inefficiencies, and each one handles exactly the format its name says, so a format you do not want re-encoded can be turned off by name without touching the others.

How each format is recompressed

recompress_jpeg keeps a re-encode only when it is smaller than the original by the margin ImageLimitOptimizedPercent sets (default 100: any reduction at all), and a losing re-encode is remembered so the same JPEG is not re-encoded on every request. The filter is a CoreFilter through rewrite_images and also part of OptimizeForBandwidth; disabling it by name while keeping the compound on leaves the other formats recompressing.

recompress_images is a convenience filter that enables recompress_jpeg, recompress_png, and recompress_webp together with convert_gif_to_png, convert_jpeg_to_progressive, convert_jpeg_to_webp, convert_png_to_jpeg, jpeg_subsampling, strip_image_color_profile, and strip_image_meta_data.

When to use it

  • In CoreFilters, the default RewriteLevel: it runs unless you disable it.
  • Part of OptimizeForBandwidth, the level that optimizes resources without changing their URLs.
  • Also switched on by recompress_images and rewrite_images.
  • Risk rating on these docs: Generally safe.

Risks

Recompression is lossy. Setting quality too low produces visible artifacts. The default values are conservative and safe for most content. Photographic content can tolerate lower quality than screenshots or text-heavy images.

Configuration

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

Apache

ModPagespeedEnableFilters recompress_jpeg

nginx

pagespeed EnableFilters recompress_jpeg;

IIS (pagespeed.config)

pagespeed EnableFilters recompress_jpeg

It is on by default under CoreFilters; to turn it off:

ModPagespeedDisableFilters recompress_jpeg   # Apache
pagespeed DisableFilters recompress_jpeg;   # nginx
pagespeed DisableFilters recompress_jpeg   # IIS
ParameterDefaultDescription
ImageRecompressionQuality85General quality level for recompressed images (-1 to 100; -1 uses source quality)
JpegRecompressionQuality-1JPEG-specific quality; -1 uses ImageRecompressionQuality
WebpRecompressionQuality80WebP quality level

On the worker

The worker runs its own pipeline, configured by flags. Its equivalent of this filter is the image pipeline transform. Always-on baseline under pagespeed on;; there is no per-transform off switch.

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

Frequently asked questions

What does the recompress_jpeg filter do?
recompress_jpeg re-encodes JPEG images that reach it. It runs after the conversion candidates: a JPEG that was not converted to WebP or AVIF for this request is re-encoded at JpegRecompressionQuality, which defaults to -1, meaning it follows ImageRecompressionQuality (default 85). Only when ImageRecompressionQuality is itself -1 does the module keep the source file's own quality.
Is recompress_jpeg enabled by default?
Yes. recompress_jpeg is in CoreFilters, the default RewriteLevel, so it runs unless you turn it off with DisableFilters. It is also part of the OptimizeForBandwidth level.
How do I turn off recompress_jpeg?
Add ModPagespeedDisableFilters recompress_jpeg on Apache or pagespeed DisableFilters recompress_jpeg; on nginx. On IIS, add pagespeed DisableFilters recompress_jpeg to pagespeed.config.

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

Search