Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Implement H2 Early Hints for Rails #30744
When puma/puma#1403 is merged Puma will support the Early Hints status
While the Early Hints spec is still in draft, this PR prepares Rails to
If the proxy server supports Early Hints, it will send H2 pushes to the
This PR adds a method for setting Early Hints Link headers via Rails,
Once puma supports Early Hints the
To start the server with Early Hints enabled pass
This has been verified to work with h2o, Puma, and Rails with Chrome.
The commit adds a new option to the rails server to enable early hints
Early Hints spec:
cc/ @tenderlove who I worked with on this feature
In the screenshot below you can see the pushes from early hints.
just a bad pattern in general and not dry ... so prefer to avoid even if it's fine here…
According to code, links for early hints are formatted even when server does not support early hints. Should this be better enabled with
Also this should be a better option to provide method to send hints from controller, this way browser can start loading scripts even before server starts business logic and page rendering. Layout rendering is the last stage (except streaming mode) of request processing, hints can be even earlier (in before_action?).
Hey @eileencodes! Thanks so much for your work getting early hints supported in Rails.
I'm seeing some intermittent socket timeout errors when I have --early-hints enabled on my app, which is hosted on Heroku. It's only showing up about once a day, and only in production.
Some lucky visitor's request is throwing one Puma:ConnectionError for each
Hey @pjforde1978 I'm not sure what's going on but I suspect that this is more on the puma side than the Rails side since Rails just adds the tags, but Puma makes the early hints actually work. Can you open an issue over there including what your application is using (Ruby version, Rails version, Puma version, proxy you're using), and anything else that can help us track this down. Unfortunately we're not able to use this in prod at GitHub yet so I'm not sure where to start looking.
Message for Eileen:
Hi @eileencodes, thanks for adding this fantastic feature.
I've been investigating the error reported by @pjforde1978. This happens if the connection is lost before we're able to send any response headers. Rails will try to write the early hints on a socket which no longer exists so it'll fail. This happens very rarely and probably no end-users are being affected as I'm assuming the connection is lost when the user abandons the page load.
From Rails' perspective, there's nothing we can do if the socket has been closed. I think we can ignore this error safely.
But do you think Rails should bother to abort completing this request if the early hints report a lost connection somehow?