GamendWeb.BrotliCompressor (gamend_web v1.0.1216)

Copy Markdown View Source

A Phoenix.Digester.Compressor that shells out to brotli.

Add it beside the gzip one and mix phx.digest writes a .br next to every .gz; GamendWeb.Endpoint serves them when :brotli_static is on.

config :phoenix, :static_compressors, [
  Phoenix.Digester.Gzip,
  GamendWeb.BrotliCompressor
]

Which files are compressed is :phoenix, :gzippable_exts — one list, so a host that adds an extension (a Godot web export's .wasm, say) gets both encodings from the one setting rather than two lists that drift.

Shelling out

Quality 11 is a build-time cost paid once per asset, and the brotli CLI is present in the Docker image. There is no NIF here on purpose: an Elixir brotli dependency would need a compiler on every machine that builds assets, to save a System.cmd that runs a few dozen times in a release build.

Every failure mode returns :error, which makes the digester skip the file and keep the gzip: a missing binary, a non-zero exit, or output that came out no smaller than the input — the last of which is why the size check is in the match rather than an if after it.