bext-plugin-image-opt

On-the-fly image optimization with WebP/AVIF conversion and blur placeholders.

$ bext plugin add image-opt
Version 3.0.1
Sandbox wasm
Author bext-team
License MIT
Downloads 8,219
Updated 2026-04-01

Intercepts image responses and optimizes them on the fly. Converts to WebP or AVIF based on the client's Accept header. Generates blur placeholder data URIs for above-the-fold images. Compiled to WASM for near-native performance.

Install

bext plugin add image-opt

Config

[plugins.image-opt]
quality = 80
max_width = 2048
formats = ["webp", "avif"]
blur_placeholders = true
cache_ttl = "7d"

How it works

The plugin hooks into `onResponse`. When it sees a response with an image content-type, it:

1. Checks the request's `Accept` header for WebP/AVIF support 2. Resizes if the image exceeds `max_width` 3. Re-encodes in the best supported format 4. Sets aggressive cache headers 5. Optionally generates a 32px blur placeholder and stores it in a response header (`X-Blur-Hash`)

Images that are already smaller than the optimized version are passed through untouched.

Supported formats

Input: JPEG, PNG, GIF, BMP, TIFF, WebP. Output: WebP, AVIF, or original format if neither is accepted.

Performance

The WASM sandbox adds ~2ms overhead per image on first request. Subsequent requests hit the CDN cache.