All Projects → hauleth → phoenix_bakery

hauleth / phoenix_bakery

Licence: MIT License
Better compression for your Phoenix assets

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to phoenix bakery

phoenix assets webpack
Asset Pipeline with Webpack on Phoenix
Stars: ✭ 52 (+108%)
Mutual labels:  phoenix, assets, phoenix-framework
pokerex client
Elm client for PokerEx project
Stars: ✭ 39 (+56%)
Mutual labels:  phoenix, phoenix-framework
game of life-elixir
An implementation of Conway's Game of Life in Elixir
Stars: ✭ 22 (-12%)
Mutual labels:  phoenix, phoenix-framework
gringotts payment
Demo Phoenix app showing gringotts payment library integrations.
Stars: ✭ 24 (-4%)
Mutual labels:  phoenix, phoenix-framework
Phoenix And Elm
Example application using Elixir, Phoenix and Elm
Stars: ✭ 188 (+652%)
Mutual labels:  phoenix, phoenix-framework
Realtime
Listen to your to PostgreSQL database in realtime via websockets. Built with Elixir.
Stars: ✭ 4,278 (+17012%)
Mutual labels:  phoenix, phoenix-framework
live dj
💿 Join or create video playlists to share a real-time experience with others! 🎧
Stars: ✭ 19 (-24%)
Mutual labels:  phoenix, phoenix-framework
Phoenixsharp
C# Phoenix Channels client. Unity Compatible.
Stars: ✭ 96 (+284%)
Mutual labels:  phoenix, phoenix-framework
poker ex
Texas Hold 'Em app written in Elixir with Phoenix and OTP
Stars: ✭ 58 (+132%)
Mutual labels:  phoenix, phoenix-framework
king of tokyo
👑 King of Tokyo Multiplayer Board Game using Phoenix LiveView
Stars: ✭ 25 (+0%)
Mutual labels:  phoenix, phoenix-framework
phoenix bootstrap form
Bootstrap 4 Forms for Phoenix/Elixir Applications
Stars: ✭ 38 (+52%)
Mutual labels:  phoenix, phoenix-framework
Tune
A streamlined Spotify client and browser with a focus on performance and integrations.
Stars: ✭ 166 (+564%)
Mutual labels:  phoenix, phoenix-framework
Phoenix Liveview Counter Tutorial
🤯 beginners tutorial building a real time counter in Phoenix 1.5.5 + LiveView 0.14.7 ⚡️
Stars: ✭ 115 (+360%)
Mutual labels:  phoenix, phoenix-framework
pryin
PryIn is an Application Performance Monitoring platform for your Elixir/Phoenix application.
Stars: ✭ 25 (+0%)
Mutual labels:  phoenix, phoenix-framework
Elixir Companies
A list of companies currently using Elixir in production.
Stars: ✭ 1,475 (+5800%)
Mutual labels:  phoenix, phoenix-framework
zero-to-graphql-using-elixir
The purpose of this example is to provide details as to how one would go about using GraphQL with the Elixir Language.
Stars: ✭ 20 (-20%)
Mutual labels:  phoenix, phoenix-framework
Shorten api tutorial
🔗How to make a link shortener using Elixir, Phoenix and Mnesia
Stars: ✭ 60 (+140%)
Mutual labels:  phoenix, phoenix-framework
Memento
Collect saved items from different sources around the web
Stars: ✭ 89 (+256%)
Mutual labels:  phoenix, phoenix-framework
phoenix-liveview-15m.twitter
Based on the "real-time Twitter clone in 15 minutes with LiveView and Phoenix", from Chris McCord
Stars: ✭ 40 (+60%)
Mutual labels:  phoenix, phoenix-framework
elixir jobs
A job board to publish and find Elixir offers.
Stars: ✭ 83 (+232%)
Mutual labels:  phoenix, phoenix-framework

PhoenixBakery

Better compression for your Phoenix assets.

This is set of modules that implement Phoenix.Digester.Compressor behaviour which can be used together with Phoenix 1.6 or later for better compression of the static assets served by Plug.Static.

Installation

First thing to do is to add PhoenixBakery as a dependency.

def deps do
  [
    {:phoenix_bakery, "~> 0.1.0", runtime: false}
  ]
end

And configure your Plug.Static:

plug Plug.Static,
  encodings: [{"zstd", ".zstd"}],
  gzip: true,
  brotli: true,
  # Rest of the options…

WARNING: Current release of Plug (1.12.1) do not support :encodings option yet and this option is ignored. So Zstandard-compressed files will not be served to the clients, even if client will have support for such format. Future releases of Plug however should make it work as expected. See elixir-plug/plug#1050.

Then you need to configure your compressors via Phoenix configuration:

config :phoenix,
  static_compressors: [
    # Pick all that you want to use
    PhoenixBakery.Gzip,
    PhoenixBakery.Brotli,
    PhoenixBakery.Zstd
  ]

Supported compressors

PhoenixBakery.Gzip

Replacement of default Phoenix.Digester.Gzip that provides better default compression ratio (defaults to maximum possible) instead of default option that compromises between compression speed and compression ratio.

It uses built-in zlib library, which mean, that there is no external dependencies and it will work OotB on any installation.

Configuration

PhoenixBakery.Gzip provides 3 different knobs that you can alter via application configuration:

config :phoenix_bakery, :gzip_opts, %{
    level: :best_speed, # defaults to: `:best_compression`
    window_bits: 8, # defaults to: `15` (max)
    mem_level: 8 # defaults to: `9` (max)
  }

The shown above are defaults. For description of each option check zlib documentaion

PhoenixBakery.Brotli

Brotli is algorithm that offers better compression ratio when compared with Gzip, but at the cost of greater memory consumption during compression. It provides quite good decompression speed. It is supported by all major modern browsers

Requirements

To use PhoenixBakery.Brotli you need at least one of:

  • Add {:brotli, ">= 0.0.0", runtime: false} to use NIF version of the Brotli compressor. It requires C code compilation and it can slow down compilation a little as the compilation isn't the fastest.
  • Have brotli utility available in $PATH or configured via config :phoenix_bakery, :brotli, "/path/to/brotli"

If none of the above is true then compressor will raise.

Configuration

config :phoenix_bakery,
  brotli_opts: %{
    quality: 5 # defaults to: `11` (max)
  }

PhoenixBakery.Zstd

Zstandard is algorithm that offers quite good compression ratio when compared with Gzip, but slightly worse than Brotli, but with much better decompression speed. It is currently not supported by browsers, but is already IANA standard, so the rollout of the support should be pretty fast.

Requirements

To use PhoenixBakery.Zstd you need at least one of:

  • Add {:ezstd, "~> 1.0", runtime: false} to use NIF version of Zstd compressor. It requires C code compilation and git tool to be available to fetch the code of zstandard code.
  • Have zstd utility available in $PATH or configured via config :phoenix_bakery, :zstd, "<path-to-zstd-executable>/zstd"

If none of the above is true then compressor will raise.

Configuration

config :phoenix_bakery,
  zstd_opts: %{
    level: 10 # defaults to: `22` (ultra-max)
  }

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 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].