HTTP/2 Support in Rack / Rails
Asked Answered
P

2

23

HTTP/2 is released and supported by all major browsers. There are implementations shipping in major web servers like Apache and nginx.

But for us Rubyists, the choices are currently quite limited, it seems. Once upon a time (Dec 2014), Aaron Patterson was exploring ideas for supporting HTTP/2 in Rack 2.0, but that hasn't yet materialized. He's also posted a few gists with possibilities for Puma and WEBrick. That's all I've managed to find.

My question is, broadly: if I am interested in using HTTP/2 in a Rails app, what options exist, which features of HTTP/2 do they include, and are any of them ready for production?

Pleurisy answered 16/10, 2015 at 17:44 Comment(0)
I
6

As of April 2018, Rails v5.2.0 now includes HTTP/2 Early Hints to send assets before the main request (asset pushing):

https://weblog.rubyonrails.org/2018/4/9/Rails-5-2-0-final/

Note: you'll still need a version of Puma that takes the --early-hints flag at startup (e.g. v3.11.4).

Indiraindirect answered 25/4, 2018 at 17:56 Comment(0)
P
10

If you want to claim to support HTTP/2 for its own sake, you can just run NGinX with HTTP/2 and use a Ruby backend, roughly as normal (https://www.nginx.com/blog/how-nginx-plans-to-support-http2/). That won't give you HTTP/2-specific features like pushing assets from the server without a client request, though.

I believe it will give you the basic HTTP/2 feature you care about, multiple requests per connection (no slow-start) and muxing on a connection (don't need multiple connections.)

So that's nice.

Parch answered 16/10, 2015 at 18:39 Comment(3)
Thanks for the answer. I'll accept it for now, but I'd love to hear other options — including (of course) something that'd work on Heroku, if possible. If memory serves, it's possible to run nginx on Heroku, but that defeats the purpose of using Heroku for me, as I suddenly have to worry a lot more about configuration and deployment.Pleurisy
HTTP2 will bring a new set of architectural practices that will need to be evaluated and implemented. Let's say caching: you would want to stop doing concatenation…Chevaldefrise
Using Cloudflare will automatically get you basically the same benefits as those mentioned above with nginx, and can sit in front of Heroku. It even supports server push, though not particularly well in combination with Rails.Pavlov
I
6

As of April 2018, Rails v5.2.0 now includes HTTP/2 Early Hints to send assets before the main request (asset pushing):

https://weblog.rubyonrails.org/2018/4/9/Rails-5-2-0-final/

Note: you'll still need a version of Puma that takes the --early-hints flag at startup (e.g. v3.11.4).

Indiraindirect answered 25/4, 2018 at 17:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.