I’ve been trying to see if Phoenix supports HTTP/2 but I am not able to see any hint of a sign of negotiation or how to PUSH data over HTTP/2? It would be nice if, say, the View’s could specify mandatory files to be pushed to the browser based on their knowledge of the templates for example. Is there something that I am missing?
That’s a feature of Cowboy. Here’s the issue: https://github.com/ninenines/cowboy/issues/853
OK, so the situation is as follows:
- Cowboy has just got support for HTTP/2. I do not think it’s complete nor stable at the moment.
- HTTP/2 in Elixir is going to be mainly handled by Plug.
- Plug may require some significant changes to support HTTP/2 fully
- Plug/Phoenix guys are waiting for the final/stable Cowboy’s implementation before they make any moves towards HTTP/2 support. Which is probably reasonable.
I figured that might be the case. I saw the issue in cowboy and thought HTTP/2 in it was dead as the issue appears dead and figured Phoenix was either waiting (fruitlessly based on the cowboy issue) on cowboy or was building their own but could not find anything for one way or the other. I am most curious in the PUSH aspect of HTTP/2 so I await to see what they come up with to support that. Is there any timeline on it all?
I think on the Cowboy’s side, it’s going to be around 6 months to stabilize things from what I’ve been told.
On Elixir’s side - not sure. I would expect preliminary protocol support first, with no assets push and only after some time inclusion of these. It needs to be handled on plug and phoenix level, so it’ll take time before used to full potential.
This is a weakest point of Erlang/Elixir web stack and could be a real challenge as implementing a quality http/2 server is a significantly more complex task than http/1.1 and it has very material impact on performance.
Anyone in the know where things stand with HTTP2 support?
Here is the relevant issue: https://github.com/elixir-lang/plug/issues/258
TL;DR - there are some developers exploring HTTP2 with Plug and Phoenix already (potatosalad is awesome). There are also production ready implementations of HTTP2 in Erlang (Chatterbox) beyond the one in Cowboy master. If you need HTTP2 and you cannot wait for Plug/Phoenix, then you can always use directly from Cowboy master or Chatterbox.
Thanx for the info subscribed to the issue
Does anyone know what the latest is on this? It looks like plug was updated and works with Cowboy 2’s http/2 support. Are there any docs on using this?
There is a Cowboy2 Adapter being built for Plug at this moment actually (as well as maybe N2O support too). They seem to be working on push support and the new websocket API before full release, but it is testable now if you want.
Ahh, thanks! That’s what I was looking for.
One question: Plug is a specific API for HTTP? That is why we will have HTTP1.1 and HTTP2 but not websockets there? If we had websockets in Plug I’d probably not need full Phoenix for API projects.
Correct thus far, but that is the point of Phoenix, it is just plug with more. Just like Phoenix.PubSub is another dependency, breaking it up makes it more easily maintained.
First major bit was just merged in. ^.^
Cowboy2 support merged in a bit ago now:
As well as with a test to ensure HTTP/2 is working:
Once this is in Phoenix, I’ll be super happy to trash a lot of my workflow around JS and CSS
Is anyone interested in seeing a demo of how to get http/2 working with phoenix?
I’m using webpack to split my js into chunks and I’m serving them via http/2. So far the approach looks promising. There’s functionality in webpack to split into n chunks based on size, which looks useful, but I haven’t figured out how to dynamically include assets in a phoenix template, so that part is a WIP.
Ok, I’ll see if I can write something up soon that adds something beyond basic setup.
It’s tricky at the moment because brunch doesn’t really support breaking your bundle into multiple small files, so you need to use something like webpack, or just a bunch of static files. Doing it programatically is tricky too, because I can’t figure out how to tell phoenix view to grab all files that end in
.js in a particular folder and server them to page load.