hauleth

hauleth

PhoenixBakery - better compression for your Phoenix assets

PhoenixBakery is library for Phoenix 1.6 (and later) that provides modules implementing Phoenix.Digester.Compressor. There are currently 3 modules:

  • PhoenixBakery.Gzip that replaces default Phoenix.Digester.Gzip with stronger compression at cost of run time and memory usage. But as it is one-time action (for each release) it is IMHO better to use that build time for less transfer used later
  • PhoenixBakery.Brotli that provides support for Brotli algorithm designed by Google and currently supported in all modern browsers. It provides better compression that gzip and moderate decompression speed.
  • PhoenixBakery.Zstd that provides support for Zstandard algorithm designed by Facebook. While it is not supported by any browser (AFAIK), the support may rollout in near future. It provides slightly worse compression ratio than Brotli, but provides better decompression times.

https://github.com/hauleth/phoenix_bakery

Most Liked

hauleth

hauleth

Added new section to the README:

Compression gains

Test files are composed out of Phoenix JS 1.6.2 library and Phoenix LiveView JS 0.16.4 bundled with ESBuild 0.12.17 installed from NPM repository, bundled using command

esbuild ./js/app.js --minify --target=es2020 --bundle --outdir=../priv/static/js --color=true

First we will declare our baseline. These are “regular” bundle and minified bundle and the same files compressed with default Phoenix.Digest.Gzip compressor shipped with Phoenix:

155311	phoenix_app.js
77351	phoenix_app.min.js
34341	phoenix_app.js.gz
24393	phoenix_app.min.js.gz

These are results produced by the compressors available in this package:

34033	phoenix_app.js.gz
30323	phoenix_app.js.zst
29017	phoenix_app.js.br
24339	phoenix_app.min.js.gz
23202	phoenix_app.min.js.zst
21843	phoenix_app.min.js.br

This show us that with this input file we gain only a little bit better results for GZIP compression (<1% for non-minified and <0.5% for minified), but quite substantial for different compression methods, namely:

  • ~12% for ZSTD on non-minified file and ~5% on minified JS file
  • ~15.5% for Brotli on non-minified file and ~10.5% on minified JS file

When compared with default compression from Phoenix.

ZSTD while it provides slightly worse compression ratio it provides better decompression times, which may be preferred on slower or low powered devices.

12
Post #5
hauleth

hauleth

Released v1.0.0

It is mostly done, so I decided to release v1.0.0

New things:

  • It will use OTP-provided zstd module when available (OTP 28+)
  • It will not fail if the command is not available anymore. It will warn about missing CLI tool and will simply ignore the compressor. This can lead to missing optimisations, but should not cause builds to fail.
hauleth

hauleth

Version 0.1.1 released and 0.1.0 was yanked as I spotted bug where PhoenixBakery.Gzip was producing no output due to fact that I forgot to correct output type. Added tests for that as well as set GitHub Actions for CI.

Oh, and also required Elixir version was lowered to 1.11 (due to fact that I use :tmp_dir in tests, and that prevents me from using 1.10 or earlier.

hauleth

hauleth

Released 0.1.2

Mostly fixes related to the CI, documentation and compatibility with newer Phoenix releases.

tensiondriven

tensiondriven

I’d love to see some charts showing the compression difference, if its substantial i think a lot of people would use this.

Thanks for making and sharing it!!

Where Next?

Popular in Announcing Top

zachdaniel
Ash Framework 3.0: Official Release! I’m here with the fine folks at Gig City Elixir, pushing the button live on stage :sunglasses: T...
New
MRdotB
Greetings Elixir community! Today, I’m thrilled to present you with resvg_nif, an open-source project that provides Elixir bindings for ...
New
sonic182
Hi everyone, at Doofinder we have been building llm_composer for some new apps, and we thought it could be useful to share it with the co...
New
kzemek
I’ve recently released v0.2.0 of my Python interop library, Snex. This version rolls up all work-in-progress improvements that have been...
New
munksgaard
flakify is an igniter installer that allows you to quickly get a Nix flake-based development shell up and running for your Elixir/Phoenix...
New
rms.mrcs
Hi there :waving_hand: Just dropping by to share PhonixLiveState, a lib I’ve just published. It’s still VERY RAW, but already in a reas...
New
LostKobrakai
I’ve recently created a small library phoenix_vite integrating the vite build tooling with phoenix. It provides an igniter.installer t...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
Mati365
Phoenix has great tooling overall, but one thing that’s still lacking is a solid, plug-and-play integration with a modern WYSIWYG editor....
New
waseigo
I saw this LinkedIn post: *Can your programming language do this? This is a macro in Clojure called `dotrace`. When you surround a pie...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

We're in Beta

About us Mission Statement