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?

ivanreese
  • 2,718
  • 3
  • 30
  • 36

2 Answers2

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.

Noah Gibbs
  • 765
  • 3
  • 10
  • 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. – ivanreese Dec 03 '15 at 23:19
  • 1
    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… – Alex Escalante Jan 23 '16 at 04:08
  • 1
    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. – Jason May 05 '16 at 18:59
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).

xiy
  • 808
  • 6
  • 13