Announcement & RFC: Pixbooster module

Modern image file formats such as AVIF, JXL and WebP seem to be powerful, overcome previous formats and are recommended by search engines. But most CMS and related tools rarely support them. So I have the idea to provide such support at the Caddy level using an http handler module: Pixbooster

After a few days of work, I managed to create a first version which do not work too badly. As this is my first module for Caddy and my first project in Go, before going further, I would like to submit my work to your code review. All comments are welcome if kindly provided!

1 Like

Very cool, thanks for sharing!

Might I suggest, instead of using httptest.NewRecorder:

Use caddyhttp.ResponseRecorder:

https://pkg.go.dev/github.com/caddyserver/caddy/v2/modules/caddyhttp#NewResponseRecorder

This type is designed to be more efficient because it only buffers if necessary.

1 Like

Thanks for your comments, @matt, as kind as always. I will make the suggested change.
Another question: the WebP library I’m using requires CGO_ENABLED=1 to compile. Is this a problem for distributing the module through the Caddy download page? I tried to find a library that didn’t require this, but couldn’t find any, except for bindings that require external libraries installed on the host.

1 Like

Yes, we don’t typically build C/cgo packages on our build server, so you’ll need to find another way to distribute that unfortunately.

I thought so. It’s a shame that WebP encoding support is so poorly implemented in Go. I think I’ll drop it. AVIF and JXL alone should make the trick.

You might be able to make it optional behind a build flag that only includes it if cgo is enabled.

// +build cgo

Thanks for the tip ! I’ll try it next monday !

Done !

1 Like