loco-rs / loco

🚂 🦀 The one-person framework for Rust for side-projects and startups
https://loco.rs
Apache License 2.0
5.52k stars 235 forks source link

Add brotli compression as the main static file precompression algorithm #979

Closed Innominus closed 5 days ago

Innominus commented 2 weeks ago

This PR adds brotli precompression to static asset file serving whilst leaving in gzip precompression as a fallback. Brotli is widely supported in major browsers and provides much better compression. If the requester does not accept brotli compression, gzip will be served as a fallback.

Also, apologies, my editor removed trailing white spaces from the .md file. Happy to add them back if you want a cleaner PR.

Sillyvan commented 2 weeks ago

Nowdays i see most services default to zstd instead. Brotli is amazing but its also a lot more resource heavy. Maybe zstd would be a better default

Innominus commented 2 weeks ago

Nowdays i see most services default to zstd instead. Brotli is amazing but its also a lot more resource heavy. Maybe zstd would be a better default

I'm happy to add zstd as the default option so there's 3 options. I guess it's up to the maintainers and general consensus on what people would prefer. Can update when there's more input.

Innominus commented 2 weeks ago

Making it configurable in future might be the best outcome.

jondot commented 5 days ago

hi, we're going to stay with gzip as it's the most universal but we'll be happy to accept a PR that makes this more configurable or composable. closing this for now

Innominus commented 5 days ago

This doesn't stop anyone from just using gzip, but if the header accepts brotli as an encoding and you have a brotli version of the file it would serve that instead. Understandable though if you don't want these methods clogging up the file and prefer it to just be configurable in future, I can understand that. Thanks.