Hacker News new | ask | show | jobs
by tootie 3902 days ago
How would server push from a web server work?
3 comments

Other comments are are good starts.

Another method would be to add a headers to the response:

    Server-Push: /relative/url
Then have an output filter pull them out and push them -- but AFAIK the APIs to do that don't yet exist in mod_h2 to push like that. Adding headers in the response is nice because it works with any 'backend', and the web server doesn't have to parse the HTML/css/etc going the through it.
This how it's done in mod_spdy[1] and App Engine[2], with the X-Associated-Content header.

[1]: https://code.google.com/p/mod-spdy/wiki/OptimizingForSpdy#Us... [2]: https://github.com/GoogleChrome/http2push-gae

The simplest way would seem to be a directive to push static resources:

    <Location />
        ServerPush /static/css/main.css
        ServerPush /static/js/main.js
    </Location>

    <LocationMatch "^/$">
        ServerPush /static/img/gigantic-homepage-image.jpg
    </LocationMatch>

    <Location /maps/>
        ServerPush /static/js/leaflet.js
    </Location>
I believe this could even avoid the need to include cache-busters in the URL since you could push with an ETag and the client can terminate if it already has the appropriate bytes without the incredible performance hit of using ETags with HTTP 1.
I think this is unsustainable (any non-trivial change to your html resources would require updating and restarting httpd). This is not DRY.

Jetty's approach to this problem is really interesting. Using HTTP referrer headers, it builds up a tree of resources that are often fetched together. Then, it optimistically pushes companion resources down. https://github.com/eclipse/jetty.project/blob/master/jetty-s...

You'll note that I said “simplest” – this could work on a $2/month shared hosting plan (not sure where you got the “updating and restarting httpd” bit from with a couple decades of prior art showing otherwise).

The Jetty approach is clever, too, as would be things like scanning rel=prefetch links but simple declarative approaches have their moments, too. One thing the Jetty approach doesn't appear to offer is the ability to manage resources if not all resources are appropriate for every client so it would appear to do things like ship every size of a responsive image to every client.

If the server can parse served html, it could preemptively also send along other required assets (css, images, etc) before the client has time to parse and request them. This would help remove necessity for optimizations like image bundling.