You should never use GIF anymore, it is super inefficient. Just do video, it is 5x to 10x more efficient.
But I fully realize, there are vanishingly few cases with similar constraints.
Or you could use content-negotiation to only send avif when it's supported, but IMO the HTML way with <picture> is perhaps clearer for the client and end user.
I think the webp problem was due to browsers supporting webp but not supporting animation, transparency or other features, so content negotiation based on mime types (either via <picture> or HTTP content-negotiation) did not work properly. Safari 16.1-16.3 has the same problem with AVIF, but that is a smaller problem than it was with webp.
> Safari 16.1-16.3 has the same problem with AVIF, but that is a smaller problem than it was with webp.