Loading...

CDN.com.tr Help

Image optimization: AVIF and WebP at the edge

Switch on image optimization for the account or for one delivery rule and choose WebP or WebP + AVIF: the edge converts JPEG and PNG images and sends each browser a format it accepts, while your pages keep the same image URLs.

Image optimization: AVIF and WebP at the edge

Switch on image optimization for the account or for one delivery rule and choose WebP or WebP + AVIF: the edge converts JPEG and PNG images and sends each browser a format it accepts, while your pages keep the same image URLs.

Related guides

The measurements behind the format choice, a checker for any page, and the purge guide.

Format choice

AVIF vs WebP, measured

Which format is smaller on photos, screenshots and icons, with the bytes.

Read the guide
Any page

Image format checker

The format a page's images reach a modern browser and a plain client in.

Open the checker
After switching

Purge cached content

Clear the copies cached before the switch so they are converted again.

Open topic

Panel path

  1. Management Panel
  2. Delivery Rules
  3. Image optimization
  4. Image format

Prerequisites

  • A CDN account whose site is served through the edge.
  • The owner or editor role: viewers can see the settings and run the image check, but cannot change them.
  • Know which paths need hotlink protection, signed URLs or a rate limit: a rule with image optimization on applies none of them, and the account switch lifts them from JPEG and PNG files.

Decision model

Whole account or one rule?

The account switch covers JPEG and PNG files on every rule. A rule switch covers only that rule's paths, a good way to try it on one folder or one domain first.

  • Account-wide: for a site whose images are public
  • Per rule: one folder or domain first, while the other rules keep their protections

WebP or WebP + AVIF?

The format is set once for the account and applies wherever image optimization is on.

  • WebP: almost every browser in use, lower processing cost
  • WebP + AVIF (automatic): AVIF for the browsers that accept it, usually the smallest on photos

Step-by-step guide

1

Turn on image optimization

The account switch is the quickest start; a rule switch limits it to that rule's paths.

  • Open Delivery Rules and select the account.
  • Turn on Account-wide image optimization, or open a rule and turn on image optimization there.
  • Save, and wait until the change is published to the edge.

Expected result: JPEG and PNG requests on those paths are converted at the edge.

cdnctl equivalent
curl -s -X POST -H "Authorization: Bearer $CDN_TOKEN" -H 'Content-Type: application/json' -d '{"type":1}' https://cdn.com.tr/api/accounts/$ACCOUNT_UUID/image_optimization
# one rule instead: set "image_optimization":"on" in the rule JSON
cdnctl cdn advanced-rules create --account "$ACCOUNT_UUID" --file rule-images.json
2

Choose the format

The format applies wherever image optimization is on, account-wide or in a rule.

  • Under Image format, choose WebP or WebP + AVIF (automatic).
  • Read the rate shown under the format before you save.

Expected result: With WebP + AVIF, browsers that accept AVIF receive AVIF from the same URLs; the others receive WebP or the image in its original format.

cdnctl equivalent
curl -s -X POST -H "Authorization: Bearer $CDN_TOKEN" -H 'Content-Type: application/json' -d '{"enabled":true}' https://cdn.com.tr/api/accounts/$ACCOUNT_UUID/image_avif
3

Purge, then check

Images cached before you switched optimization on keep their old format until they expire, so purge the image paths after switching on. A format change needs no purge.

  • Purge the image folders, or everything, under Cache Cleanup.
  • Run the image format check under the switch on one of the account's domains.

Expected result: The check lists each image with the format and size a modern browser receives; when the optimizer kept the original because the conversion was not smaller, the row says so.

cdnctl equivalent
cdnctl purge --account "$ACCOUNT_UUID" --path /wp-content/uploads/ --type prefix
curl -s -H "Authorization: Bearer $CDN_TOKEN" "https://cdn.com.tr/api/accounts/$ACCOUNT_UUID/image_check?host=www.example.com"

Verification

  • curl -sLo /dev/null -w '%{content_type} %{size_download}\n' -H 'Accept: image/avif,image/webp,*/*' https://www.example.com/photo.jpg → image/avif or image/webp (with WebP alone, image/webp after the redirect), unless the converted file was not smaller
  • curl -s -D - -o /dev/null -H 'Accept: image/webp,*/*' https://www.example.com/photo.jpg | grep -iE '^(vary|location)' → WebP + AVIF: Vary: Accept; WebP alone: Location: …/photo.jpg.webp
  • curl -so /dev/null -w '%{content_type}\n' -H 'Accept: */*' https://www.example.com/photo.jpg → image/jpeg, the original format

Use cases

A store wants lighter product photos without re-exporting its media library, installing a plugin or changing a single image URL.

Quick workflow

  1. Open Delivery Rules for the account.
  2. Turn on account-wide image optimization, or turn it on in one rule to start with that rule's paths.
  3. Under Image format, choose WebP or WebP + AVIF (automatic) for the account.
  4. Purge the images that are already cached, then run the image format check under the switch.

Checks

  • Converted: JPEG and PNG files (.jpg, .jpeg, .png). GIF, SVG and files that are already .webp go out unchanged.
  • How the format reaches the browser depends on the account's format. With WebP + AVIF, one URL answers every browser: the edge reads the browser's Accept header, sends AVIF, WebP or the image in its original format, and answers with Vary: Accept. With WebP alone, browsers that accept WebP are redirected (302) to a WebP copy at the same name plus .webp (photo.jpg.webp), and the others get the image in its original format. Your HTML keeps the same image URLs either way.
  • At full size, a newly converted image goes out only when it is smaller than the original: an AVIF that is not smaller gives way to WebP, and a WebP that is not smaller to the original. Images resized with ?w= or ?h= are not compared.
  • If a conversion fails, the edge serves the original image instead.
  • Converted images are kept for 365 days, at the edge and in browsers. Copies cached before you switched optimization on keep their old format until they expire or you purge them. Changing the format needs no purge: the edge stores each format separately, so new visitors get the new format at once, while a browser that already loaded an image may keep its copy for up to a year.
  • Hotlink protection, signed URLs and the rate limit: a rule with image optimization on applies none of them, to any file it serves. With the account switch on, JPEG and PNG files skip them on every rule that has no switch of its own. Keep image optimization off on any rule whose files need these protections, and keep the account switch off too if its JPEG and PNG files need them. An exact-path rule cannot use image optimization.
  • Processing counts toward your monthly quota, AVIF at a higher rate than WebP. The panel shows the current rate under the switch.

Frequently asked questions

Why do some images still arrive as JPEG or PNG?

Most often the copy was cached before you switched optimization on: purge those paths and request them again. Other reasons: at full size the conversion was not smaller than the original, the browser accepts neither WebP nor AVIF, or the request asked for no image format in particular (a plain curl sends Accept: */*). The image format check on the Delivery Rules page lists, image by image, what a modern browser and a plain client receive.

Can I resize images through the URL?

Yes. Add ?w= (width), ?h= (height) or both to an image URL. One value keeps the aspect ratio, both fit the image inside that box, and an image is never enlarged beyond its original size. Keep w and h in that rule's cache key (the default, the full query string, does): a rule that ignores every query parameter caches one size for all of them. Resized images are converted too, but they are not compared with the original.

How is it billed?

There is no separate package. Processing counts toward the account's monthly quota, like traffic: each conversion counts the original it reads plus the image it returns, and AVIF counts at a higher rate than WebP because encoding it takes more processing. The panel shows the current rate under the switch, and Data Consumption shows image optimization as its own line.

Do I need WebP + AVIF?

It is a choice, not a requirement. WebP alone reaches almost every browser in use. WebP + AVIF adds AVIF for the browsers that accept it, usually the smallest format for photographs: in our measurement a 262,025-byte JPEG photo went out as 86,936 bytes of AVIF. Run the image format checker on your own pages to see the difference.