Enable vary for images
Vary for Images is enabled through Cloudflare’s API by creating a variants rule. In the examples below, learn how to serve JPEG, WebP, and AVIF variants for .jpeg
and .jpg
extensions.
Create a variants rule
curl -X PATCH -H "X-Auth-Email: user@example.com" \ -H "X-Auth-Key: 3xamp1ek3y1234" \ -H "Content-Type: application/json" \ --data '{"value":{"jpeg":["image/webp","image/avif"],"jpg":["image/webp","image/avif"]}}'
Modify to only allow WebP variants
curl -X PATCH -H "X-Auth-Email: user@example.com" \ -H "X-Auth-Key: 3xamp1ek3y1234" \ -H "Content-Type: application/json" \ --data '{"value":{"jpeg":["image/webp"],"jpg":["image/webp"]}}'
Delete the rule
curl -X DELETE -H "X-Auth-Email: user@example.com" \ -H "X-Auth-Key: 3xamp1ek3y1234"
Get the rule
curl -X GET -H "X-Auth-Email: user@example.com" \ -H "X-Auth-Key: 3xamp1ek3y1234"