I am on my way to sleep so I didn’t test it for you. (I would like the first syntax I gave you to work though, so I’ll submit a PR for that in the morning.)
Aye. Unlearning convention Caddy 1 invented is a pain point we see all over the place. Ultimately it’s important to remember that Caddy v1 and v2 are, essentially, completely different programs. There’s an absolutely massive amount of feature parity, but they’re just not the same underneath the hood at all.
Implementing automatic precompressed asset serving in Caddy v2 could be a good issue. Currently the closest one that mentions this is v2: Content negotiation · Issue #2665 · caddyserver/caddy · GitHub, but it’s not explicitly for this feature, only some functionality that would make this feature easier.
Okay i got one more problem. After i enable this brotli thing all my svg images stop loading and displaying in img tag. I believe it’s related to mime types.
Do all these SVG images have a Brotli sidecar as well?
Content-Type could be an issue. We are only strictly overriding the Content-Encoding in the config, but the issue could be showing up at the file server.
Does that issue (image not loading) also happen for PNG, JPEG etc. files with a Brotli sidecar?
It doesn’t happen because it doesn’t make sense to encode PNG and JPEG with brotli, but svg is basically text. I only use brotli for static text files.
Ah, now I remember why content negotiation is tricky: the Content-Type header is based on file extension, so adding .br to the extension breaks the lookup in the MIME tables.
It may not be ready before 2.0, but if not it can come after.
Edit: So, yes, there is a solution, but it’s a bit verbose; you can always set the Content-Type header yourself, but it’ll be different for each different kind of file you serve. Still, if it’s a pretty standard static site, there won’t be more than ~5-10 types.
header gets executed before handle and rewrite, so theoretically we can easily manually re-specify the Content-Type based on the request without even messing with the existing Brotli sidecar detection/rewrite. The file server should leave the manually-set Content-Type header alone, I think?