Should you compress images before your CDN re-en...

Should you compress images before your CDN re-encodes them? Measured through Next.js, wsrv.nl and Photon

By SJ
7 min read
Iminify blog cover on a blue gradient with a pixel pattern: "Should you compress before your CDN does?"
On this page

The Fjord, one of our five test photographs, is an 852,461-byte JPEG, the master every score below is measured against. Iminify's Smart level makes it a 568,598-byte JPEG. We sent both through Next.js 16.4.3's image optimizer at its default, WebP at quality 75. Next's WebP of the master weighed 321,790 bytes and scored 66.98 against the master on SSIMULACRA 2, where 100 means no difference from the master. Its WebP of the Smart file weighed 314,578 bytes and scored 64.30: 2.2 percent fewer bytes for 2.7 points.

Should you compress before a CDN or optimizer re-encodes your image? In our tests, on five JPEG photographs through Next and wsrv.nl, only losslessly. A lossless repack, which made our uploads 2.4 to 5.6 percent smaller, changed nothing in 80 of 80 Next responses. And in 40 of 40 comparisons at no more bytes, asking Next for a lower quality setting scored higher than the lossy first pass. If nothing re-encodes after you, compress first.

A lossless repack changed nothing Next or wsrv.nl sent

Iminify's Lossless level rewrites how a JPEG's coefficients are packed and leaves the pixels alone (25 files checked in an earlier post). On our five photographs it saved 2.4 to 5.6 percent of the master, and every file scored 100.00 against it.

Through Next, the five Lossless files produced the same bytes as the five masters: 80 of 80 responses had the same SHA-256. That is two runs of 40 requests, each for five photographs at two widths, as WebP 75 and JPEG 75 under Next's defaults and as WebP 75 and WebP 90 with qualities: [75, 90]. (JPEG is Next's answer to a browser that lists neither WebP nor AVIF.) wsrv.nl, a public image proxy, did the same, as JPEG and as WebP, on all five photographs.

At 1800 px and WebP 75, a Smart first pass trims 2 to 13 percent off what Next sends and costs 3 to 8 points

Next's default WebP 75, at the photographs' own 1800 pixels, each cell the median of the five photographs. Smart is Iminify's default level and Ultra its most aggressive:

Upload Upload size Delivered size Score against the master
Master 396,520 B 73,188 B 66.98
Lossless 383,500 B 73,188 B 66.98
Smart 128,292 B 67,964 B 61.27
Ultra 76,903 B 62,706 B 55.30

Per photograph, Smart's delivered file was 86.7 to 97.8 percent of the master's delivered file and scored 2.7 to 8.2 points lower. Ultra's was 82.2 to 92.8 percent and scored 8.1 to 14.5 lower.

Cloudflare's Polish compression page (updated 21 April 2026) says: "Re-encoding of files that are already optimized reduces their quality more than it reduces their file size." Next's second pass took 27 to 48 percent off the bytes of the Smart uploads and 8.6 to 22.2 points off their scores, which are different units.

Asking Next for a lower quality scored higher in all 40 comparisons

We asked Next for each master at twenty qualities from 50 to 90. For every lossy route (a Smart or Ultra upload and one Next setting) we took the highest of those qualities whose WebP of the master was no bigger than the route's file, and compared scores. Next's WebP of the master scored higher in all 40 comparisons (Smart or Ultra, delivered at WebP 75 or 90, two widths, five photographs), by 0.12 to 13.88 points, median 4.06.

On the Fjord, the Smart route's 314,578 bytes scored 64.30. Next's WebP of the master at quality 72 was 309,732 bytes and scored 65.55.

Scatter chart for the Fjord at 1800 px, score against bytes. The master through Next at twenty qualities runs from 243,122 bytes at 57.4 to 590,444 bytes at 83.1. The four lossy-first routes, Smart or Ultra then WebP 75 or 90, all sit below that curve, from 55.8 at 289,188 bytes to 77.3 at 562,868 bytes.

Median gain in points, by route At 1800 px At 1080 px
Smart, then WebP 75 +2.36 +0.93
Ultra, then WebP 75 +8.20 +2.55
Smart, then WebP 90 +5.46 +1.61
Ultra, then WebP 90 +12.33 +5.87

Next only serves the qualities in its qualities list, 75 by default. Listing a lower one is how you ask Next for fewer bytes.

The same comparison for wsrv.nl's WebP, on the ten Smart and Ultra uploads it covers, was won by the master's WebP in 10 of 10 cases, by 1.22 to 10.28 points. Its WebP of a master matched Next's byte for byte on each of the ten photograph and quality pairs those cases needed, so Next's sweep stands in for wsrv.nl's.

A second pass can hand you a file bigger than the one you uploaded

Delivered size as a percent of the upload, at 1800 px, over the five photographs:

Optimizer Smart upload Ultra upload
Next, WebP 90 99 to 152 (bigger on 4 of 5) 151 to 172 (5 of 5)
wsrv.nl, JPEG at its default quality 80 79 to 122 (bigger on 3 of 5) 115 to 133 (5 of 5)

Our WebP post found that a JPEG saved at 80 gives a bigger WebP from about quality 90.

What wsrv.nl and Photon did to the same files

wsrv.nl defaults to quality 80. Asked for WebP with output=webp, it delivered the Smart uploads at 75 to 97 percent of its WebP of the master and 3.6 to 8.8 points lower.

Photon, Jetpack's image CDN, answers a browser that lists WebP differently from one that doesn't. Asked for a JPEG, it returned the Lossless, Smart and Ultra files byte for byte (15 of 15) and the masters at 95.5 to 99.0 percent of their size, still scoring 100.00. Asked for WebP by a browser that lists it, as Chrome does, Photon matched wsrv.nl byte for byte on the five masters and the five Lossless files. For the lossy uploads it sent smaller files than wsrv.nl in nine of ten cases; the exception is the Fjord's Smart file. The Fjord's Ultra file came back as 231,974 bytes against wsrv.nl's 344,010, and scored 50.32 against 59.20. Photon's WebPs of the five Smart uploads weighed 38.5 to 97.1 percent of its WebP of the master and scored 3.6 to 23.0 points lower.

Cloudflare and Cloudinary: documented, not tested

Polish is not on the Free plan. Its compression page recommends origin JPEGs at quality 80 to 90, because blocky low-quality ones make bigger WebPs, and says "It does not make sense to apply lossy optimizations twice to images, because quality degradation will be larger than the savings in file size." We didn't run it: it needs a paid zone and a setting on a live site.

Cloudinary's q_auto documentation lists four presets and says nothing about sources that are already compressed. Its demo cloud answered fetches of six of our files with x-cld-error: ACL deny, so we sent none through it.

What to upload

  1. If something re-encodes after you, upload the master or its lossless repack and set the quality at the optimizer. Squarespace, for one, encodes its copies itself.
  2. If nothing does, compress first: Smart took the Fjord from 852,461 to 568,598 bytes, and Photon's JPEG path delivered it as it came. A browser that lists WebP gets Photon's second pass instead.
  3. To find out which one you have, fetch your image through your site and compare it with the file you uploaded, sending the Accept header a current browser sends. Photon answers it; wsrv.nl ignores it. Our check on wsrv.nl:
curl -sf -o upload.jpg https://www.iminify.com/image/showcase/photo-landscape/smart.jpg
curl -sf -o delivered.jpg -H 'Accept: image/avif,image/webp,image/*,*/*;q=0.8' 'https://wsrv.nl/?url=https://www.iminify.com/image/showcase/photo-landscape/smart.jpg'
wc -c upload.jpg delivered.jpg

Different sizes mean something rewrote the file: here 568,598 bytes became 449,828. A score against your original shows whether it lost quality.

How we measured

The photographs are the five JPEG masters of our corpus, 1800x1200, saved at quality 92, so every score says how far a file is from that JPEG, not from a camera original. The Lossless, Smart and Ultra files are Iminify's jpg output of each, the files its showcase serves; we re-ran all 15 through the API on 1 November 2026 and got identical SHA-256 on 15 of 15.

Next ran 16.4.3 in a container on sharp 0.35.5, a copy of the harness of our Next.js post: its answers for the five masters matched that post's outputs on 40 of 40 SHA-256, and a second run of all 160 requests (40 for each of the four uploads) returned identical bytes. Quality 90 came from qualities: [75, 90]. Next accepts at most twenty qualities, so the sweep used 50, 55, 58, 60, 62, 64, 66, 68, 70, 72, 74, 75, 76, 78, 80, 82, 84, 86, 88 and 90. We scored every answer with ssimulacra2 from libjxl v0.12.0 after decoding with djpeg or dwebp, against the master resized by sharp the way Next does, written losslessly. wsrv.nl and Photon answered curl requests on 1 November 2026 at the photographs' own size, and each file is scored against the master. We tested five photographs, WebP and JPEG, not AVIF.

Questions this post answers

Share this post

Share on X
Share on Facebook
Share on LinkedIn
Share on Reddit
Share on Hacker News
Email
Copy link
Link copied
Bar chart of file sizes for a photo at four print sizes, 8x10 to 24x36. PNG bars run from 11.3 to 70.6 MB and JPEG bars from 1.4 to 6.5 MB, with a dashed line at Etsy's 20 MB limit.

How many pixels does an AI print need? 300 per inch, and at 16x20 our PNG is over Etsy's download limit

The usual answer is 300 pixels per inch of print: 2400 x 3000 for an 8x10, 4800 x 6000 for a 16x20, 7200 x 10800 for a 24x36. A square Midjourney 8.2 HD image is 2048 x 2048 and a square Gemini 4K image is 4096 x 4096, so neither reaches a 16x20 at that rate without more pixels. (Shops write DPI. Here it means pixels per inch of print.) From a 4K Gemini picture we made 16x20 files of 4800 x 6000 pixels: the PNG is 35.8 MB, over Etsy's 20 MB per file for digital downloads, and the JPEG is 3.6 MB.

7 min read
Two rows of seven squares, one per test post. After the default wp media regenerate, four squares are red and read 404 and three read 200; after --skip-delete and the rewrite, all seven read 200.

Convert your existing WordPress images to WebP without a plugin: what regenerate breaks

On a WordPress 7.1.4 test site, one filter and wp media regenerate turned the resized copies WordPress makes of five full-colour (4:4:4) photographs into WebP files with 62.5% of the JPEG copies' bytes. All 25 WebP copies, five sizes of each photograph, also scored lower. The filter and regenerate also left four of our seven test posts pointing at copies WP-CLI had just deleted, and took the srcset off all seven inserted images that had one. The version below leaves no address broken and gives six of those seven their srcset back: the filter, regenerate with one flag, and a rewrite that changes an address only where a WebP exists. The recipe as printed needs WP-CLI and a shell on the server.

8 min read
Bar chart of bytes Chrome downloaded at phone size for five 4K JPEGs on a Next.js static export page: 55.2 MB as they are, 10.2 MB as Smart JPG at full size, 1.29 MB at 1200 px wide, 767 KB through next-image-export-optimizer.

Next.js static export images: the default loader breaks them and unoptimized ships the original

We built a page with five photographs in a Next.js 16.4.3 App Router app, set output: 'export', left the image settings alone, and next build finished with exit code 0. In Chrome none of the five images loaded: every src pointed at /_next/image, an endpoint a static export doesn't contain. Setting images: { unoptimized: true } fixes that, and the export then serves the file you put in public/. Chrome at phone size downloaded 2.4 MB for five 1800 px photographs, and 55.2 MB when the same page held five 4K Gemini JPEGs. This post compares that flag, next-image-export-optimizer and resizing the files first by what Chrome downloaded at phone size and at desktop size. The table is in the second section, and the choice we'd make follows the three options.

7 min read

Try it on your own images

Drop a photograph in, pick Smart, and compare the result with the original before you download. Free, no account needed.