caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
55.53k stars 3.91k forks source link

"Encode" defaults compress already compressed font formats #6428

Closed jsheard closed 22 hours ago

jsheard commented 3 days ago

The default matcher for encode currently includes font/*, matching every font format. However, the modern WOFF and WOFF2 web font formats are already internally compressed with zlib and brotli respectively, so compressing them again is likely a waste of CPU cycles. Would it make sense to refine the defaults down to only compress the "legacy" non-WOFF formats?

https://www.iana.org/assignments/media-types/media-types.xhtml#font

mholt commented 3 days ago

Hmm, we used to do that: https://github.com/caddyserver/caddy/commit/d3f23a8eeb3b0b7198ae4c06879227b467fcfaa6

@dunglas what do you think?

dunglas commented 3 days ago

I agree. We should exclude these ones.

jsheard commented 3 days ago

I believe the formats supported by browsers pre-WOFF were TTF, OTF, EOT and SVG, with these MIME types:

font/ttf
font/otf
application/vnd.ms-fontobject (EOT)
image/svg+xml (SVG fonts don't appear to have a more specific MIME type)

Caddy already has specific matchers for EOT and SVG so I think it would only need font/ttf and font/otf to be added in lieu of font/*.

dunglas commented 2 days ago

I opened https://github.com/caddyserver/caddy/pull/6432 to fix the issue. Would you mind double-checking the patch @jsheard?