Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't compress already compressed fonts #6432

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion modules/caddyhttp/encode/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ func (enc *Encode) Provision(ctx caddy.Context) error {
"application/x-ttf*",
"application/xhtml+xml*",
"application/xml*",
"font/*",
"font/ttf*",
"font/otf*",
"font/x-woff*",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line isn't needed, WOFF is pre-compressed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://community.cloudflare.com/t/cloudflare-is-missing-the-current-woff-media-type-in-the-default-compression-config/679095, this is beneficial if Brotli (and I guess Zstandard) are used.

Brotli isn't natively supported by Caddy, but FrankenPHP and https://github.com/dunglas/caddy-cbrotli allow us to easily add support for it. Zstandard is supported and is now on by default for Chrome and Firefox (not for Safari).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, but if WOFF1 is to be compressed then the matcher should be the standardized font/woff instead of or in addition to miscellaneous names it went by before being standardized.

Copy link
Collaborator Author

@dunglas dunglas Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@jsheard jsheard Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also won't that wildcard on the end cause it to match WOFF2 anyway? AFAICT that wildcard is there in case the server appends a charset to the content type, but these are binary formats so that shouldn't happen.

For a second opinion, AWS and GCP don't compress either version of WOFF:

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html#compressed-content-cloudfront-file-types

https://cloud.google.com/cdn/docs/dynamic-compression#compressible-content

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true; I am not sure what would come after the media/type for binary types, and we could probably remove the wildcards (but that doesn't have to happen in this PR).

So we don't "woffle" over this too much longer (hehe), maybe let's remove woff for now, since even the 1.0 was also compressed. I know that article linked by @dunglas recommends compressing woff too because of "additional savings" possible at the edge, but IMO that would be quite minimal and still expensive for marginal gains.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MIME type of WOFF2 font/woff2, so it will not match, but I can remove this MIME type if you want.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WOFF removed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks; hopefully that's the best decision, but I'm not really sure, but it sounds like there is no real consensus anyway. Both WOFF versions are compressed, even if WOFF2 has "better" compression; but I don't see a need to compress either of them.

Appreciate it!

"image/svg+xml*",
"image/vnd.microsoft.icon*",
"image/x-icon*",
Expand Down
Loading