Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable compression on channels in Phoenix?

I've got a channel in phoenix that pushes out ~4KB of data, a lot of it highly repeating and was wondering if there was a way to turn on compression for that channel.

It looks fairly simple to do if I was working with a phoenix controller, but I haven't been able to find out if this is possible or documented somewhere for a channel.

Thanks a bunch.

like image 855
djdrzzy Avatar asked Jan 10 '16 21:01

djdrzzy


2 Answers

You can configure gzip compression for the responses from a particular endpoint.

config :app_name, AppName.Endpoint,
  http: [compress: true]
like image 58
Endersstocker Avatar answered Oct 21 '22 18:10

Endersstocker


As answered by Endersstocke setting http: [compress: true] in the endpoint config works, even for websockets. However there are some limitations:

Phoenix in its current version (1.3.0) or more specific: cowboy (1.1) only supports x-webkit-deflate-frame compression for websockets. From my tests I've seen that only Safari sends these requests header meaning on Chrome you will not experience any compression at all.

So if you want to have the permessage-deflate compression you will have to wait until Cowboy 2.0. See docs

like image 24
leifg Avatar answered Oct 21 '22 20:10

leifg