Gzip compression in Phoenix framework

2016/09/25 2:47pm

To compress HTTP response body from a web application powered by Phoenix framework, you have to make Phoenix.Endpoint pass compress: true property to Cowboy. In your config.exs:

config :example_app, ExampleApp.Endpoint,
  http: [port: 4040, compress: true],
  debug_errors: true,
  code_reloader: true,
  check_origin: false,
  watchers: []

When you send a HTTP request, include Accept-Encoding header. if you use the curl command, it has the option --compressed.

Accept-Encoding: gzip, deflate

However it seems that Cowboy, which is the HTTP server used in Phoenix framework, doesn’t compress response body if its size is smaller than 300 bytes.