How to Improve Rails Caching with Brotli Compression

  • Upcoming in Rails 7.1, you can specify a custom compressor for your cache, out of the box. See the `:compressor` option of `ActiveSupport::Cache::Store.new`:

    https://api.rubyonrails.org/v7.1/classes/ActiveSupport/Cache...

  • If that compression is internal-only, i'd start looking at zstd, which is much better at both speed and compression level

  • Important to understand about Brotli vs. other compression is that Brotli has been pretrained with HTML/CSS/JS code. It efficiently compresses English text and source code, especially small files, due to its static dictionary.

    https://chromium.googlesource.com/external/font-compression-...

    There are other factors that make Brotli good, but this is good to understand when dealing with web frontends.