News for hackers. Stuff that matters.
Re:A Guide to HTTP/2 Server Push by alex_duf on Monday April 10, 2017 @09:18AM (#14078226)
So wait, if the server pushes assets before the client request it, does that mean the server pushes them regardless of the cache status on the client?

If so that should really be limited to small assets to be beneficial

Re:A Guide to HTTP/2 Server Push by dfabulich on Monday April 10, 2017 @11:51AM (#14079519)
You are precisely correct; server push is not cache aware today.

According to the spec, browsers have the ability to abort pushes that the server has started, so if you start sending down a 3MB file, your browser can send the server a request to stop sending it, because it's already in cache, but no browser actually does this today, and the first part of the file gets sent down regardless.

There's a draft spec for browsers to use "Cache Digests," a compact representation of the content already in the cache. http://httpwg.org/http-extensions/cache-digest.html But no browsers support that today.

Luckily, you can workaround/polyfill Cache Digests using Service Workers. Your Service Worker can provide the Cache Digest as a custom HTTP header on subsequent requests, and then the server can know to avoid re-pushing cached resources.

Alternately, and more simply, if you configure your Service Worker to return/render stale content on first load, your Service Worker can make a request in the background to fetch the latest content, passing a simple header to the server to disable push. Since the stale content has already rendered, the round-trip time to download updated resources is less important.

http://calendar.perfplanet.com/2016/cache-digests-http2-serv...

Re:A Guide to HTTP/2 Server Push by jbergstroem on Monday April 10, 2017 @12:55PM (#14080211)
Some web servers[1] additionally stores cache information in cookies. The same author that (co-)wrote your linked draft implemented it as a primer to the draft. If only CDN's supported it :-)

[1]: https://h2o.examp1e.net/configure/http2_directives.html#http...

Re:A Guide to HTTP/2 Server Push by forgotpwtomain on Monday April 10, 2017 @07:48PM (#14083601)
> but no browser actually does this today, and the first part of the file gets sent down regardless.

Are browsers really not doing this? My understanding was that just one round-trip was wasted for the client to send an RST_STREAM frame, or does it really re-download the entire pushed file where normally it would be a 304 on request?

Re:A Guide to HTTP/2 Server Push by dfabulich on Tuesday April 11, 2017 @01:44AM (#14085154)
The RST_STREAM frame is, indeed, how the browser was supposed to abort the download, per the spec. But it's a SHOULD, not a MUST. In fact, browsers just don't do it.

So why not? Priorities. Not very many sites are using push, and this is partly due to a chicken-and-egg problem; push isn't that good, so nobody's uses it, so there's not much incentive to make push better.

But even if new browsers started correctly aborting pre-cached pushes today, that still wouldn't be as awesome as Cache Digests, which could avoid re-pushing cached content without wasting any bytes. So, if you're going to spend a few minutes working on H2 Push, you should probably spend it working on Cache Digests, rather than working on aborting pushes.

And Cache Digests can even be polyfilled by Service Workers, which are incredibly powerful in their own right. So if you're not Chrome or Firefox, rather than even spending time on Cache Digests, you should probably focus on implementing Service Workers first, so the users can at least polyfill their way out of the problem.

So the order should be: Service Workers first, then Cache Digests, then push-aborts. So, uh, don't expect to see any push aborts from the major browsers any time this year, IMO.

Re:A Guide to HTTP/2 Server Push by Ajedi32 on Monday April 10, 2017 @09:51AM (#14078481)
As I understand it, the client has an opportunity to proactively cancel pushes of assets it already has cached.

The server will send a "push promise" which basically says "I'm going to send this file to you", and then the client can come back and say "don't bother, I already have it". And this all happens in parallel with the download of other assets (like the main page), so it doesn't really slow anything down.

Here's an article I read which goes into how server push works in a lot more detail: https://hpbn.co/http2/#server-push

Re:A Guide to HTTP/2 Server Push by Matthias247 on Monday April 10, 2017 @10:58AM (#14079008)
It can slow things down, as the push works that way:

The client requests some page (e.g. index.html), which will trigger the push on the server. E.g. one for asset1.png. The server initiates the push by sending a push promise frame down the wire, which contains the content of a simulated HTTP request for that exact resource - like if the client sent a GET request for asset1.png through a headers frame. The client can only react on this frame when it receives it and sees that it has asset1.png already in cache. It can then cancel the stream by sending a ResetStream frame. However obvisouly that takes some time, until this push promise frame arrives at the client. Meanwhile the server might decide to not only send the push promise header, but also parts of (or the complete) data. So asset1.png already goes down the wire, and blocks bandwidth that could be used for other things too.

Re:A Guide to HTTP/2 Server Push by Ajedi32 on Monday April 10, 2017 @11:44AM (#14079458)
That might slow down downloads from other pages or processes, but as far as the download from the current page goes (which uses multiplexed requests and responses over a single connection) I don't see how that's any worse than it'd be without server push.

In the worst case scenario with server-push that you described, the server decides to push content the client already has cached before pushing content the client doesn't have, and begins transmitting that redundant content before the client has a chance to cancel the push. Once the client receives push promises for the content it doesn't need, it can immediately send a request to cancel the download of those resources. Once those cancellation requests reach the server, it immediately stops transmitting the resources the client has cached, and starts transmitting the data the client actually needs.

Contrast this with the same scenario without server push, where the client parses the HTML for the main page to determine what resources it needs, then send requests for those items which the server must receive before it starts transmitting them. In both cases a round-trip from the server to the client and back is needed before the server can start transmitting the necessary assets, but without server push the client needs to download and parse the main page before it can start telling the server which resources it needs, whereas with server push it can send cancellation notices before the current page is downloaded or parsed.

Re:A Guide to HTTP/2 Server Push by manigandham on Monday April 10, 2017 @03:03PM (#14081510)
The difference is that bandwidth is being used by incoming pushed assets before the abort. This might not matter much on fast wired connections but can make a big difference on mobile networks.
Re:A Guide to HTTP/2 Server Push by Matthias247 on Monday April 10, 2017 @04:13PM (#14082123)
Exactly. The start of the push will already consume downstream bandwidth until it's canceled by the remote side. I guess in the worst case it consume about up to the maximum window size of the stream (typically 64kB). The "classic" approach compared to that is the client initiating another GET request for each asset after it has received the index page. This requires more upstream traffic. However the webserver could directly respond with a 304 for cached assets, which means less downstream traffic.
Re:A Guide to HTTP/2 Server Push by Clownshoesms on Monday April 10, 2017 @10:00AM (#14078536)
I had a bit of a look around after reading the article, this page might also be useful in explaining how it interacts with the cache and some suggestions on when to apply it:

https://www.shimmercat.com/en/blog/articles/whats-push/#inte...

Sounds painful to me.

Re:A Guide to HTTP/2 Server Push by mozumder on Monday April 10, 2017 @10:19AM (#14078668)
To set it up isn't that hard... just set it and forget it, and let the browser & server handle things from there.

In practice, it's going to be a lot faster than the default of not pushing resources.

Re:A Guide to HTTP/2 Server Push by jimktrains2 on Monday April 10, 2017 @10:57AM (#14078996)
Doesn't that require more round trips than just having the client ask for it?
Re:A Guide to HTTP/2 Server Push by Ajedi32 on Monday April 10, 2017 @11:48AM (#14079486)
No, even in the worst case it's exactly the same number of round trips.

Without server push:

1. Client requests main page ->

2. Client receives main page <-

3. Client requests subresources ->

4. Client receives subresources <-

With server push:

1. Client requests main page ->

2. Client receives push promises and main page <-

3. Client cancels promises it doesn't need ->

4. Client receives subresources <-

The only difference is that with server push, steps 2, 3 and 4 happen in parallel, and step 3 can be omitted entirely in the event that the client doesn't need to cancel any pushes.

Re:A Guide to HTTP/2 Server Push by jimktrains2 on Monday April 10, 2017 @01:05PM (#14080357)
Or, what may be a more common case, depending on caching method:

Without server push:

1. Client requests main page ->

2. Client receives main page <-

With server push:

1. Client requests main page ->

2. Client receives push promises and main page <-

3. Client cancels promises it doesn't need ->

Re:A Guide to HTTP/2 Server Push by Ajedi32 on Monday April 10, 2017 @05:20PM (#14082663)
Ah, fair point. Now I see what you were trying to say.

Assuming the server has no way of determining which assets the client has cached (which depending on implementation may not be the case) you're of course correct. However, after step 2 the page has already fully loaded in both cases, so step 3 doesn't really slow anything down.

Re:A Guide to HTTP/2 Server Push by jaffathecake on Monday April 10, 2017 @11:08AM (#14079127)
Yes. This makes push better for things that you'd otherwise inline. link[rel=preload] is generally good enough for other resources.
Re:A Guide to HTTP/2 Server Push by mozumder on Monday April 10, 2017 @09:48AM (#14078464)
The H2O server, on the first request, sends a cookie that includes a signature of all the files a server pushes: https://h2o.examp1e.net/configure/http2_directives.html#http...

If, on subsequent requests, the cookie is sent along with the request, H2O doesn't send those files.

This is still a bit of a hack, and ultimately browsers will have to include some information on what's in the actual cache, with proposals on that pending: https://datatracker.ietf.org/doc/draft-ietf-httpbis-cache-di...

Re:A Guide to HTTP/2 Server Push by vfaronov on Monday April 10, 2017 @10:52AM (#14078936)
There is ongoing work at the HTTP working group to standardize “cache digests” to solve this problem:

https://tools.ietf.org/html/draft-ietf-httpbis-cache-digest

Re:A Guide to HTTP/2 Server Push by dullgiulio on Monday April 10, 2017 @09:54AM (#14078501)
Basically yes. The client can cancel the streams for pushed assets that are in cache. But the server doesn't have this information (natively) when one page is requested.

As others have said, there are workarounds using cookies. Which is yet another abuse of a very bad feature of HTTP.

Re:A Guide to HTTP/2 Server Push by youngtaff on Monday April 10, 2017 @11:54AM (#14079550)
I'm not sure that any of the current browsers actually do this though
Re:A Guide to HTTP/2 Server Push by jimktrains2 on Monday April 10, 2017 @10:36AM (#14078799)
It's unspecified how the server should handle this. AFAIK, it's "one of the great unsolved problems" with HTTP2.
Re:A Guide to HTTP/2 Server Push by Clownshoesms on Monday April 10, 2017 @09:29AM (#14078309)
I think it still obeys the browser's cache:

"When the user navigates to a subsequent page that requires that asset, it can be pulled from the cache, eliminating the need for additional requests to the server."

I'm not clear on if there is any relation to existing cache headers. I would have thought even the first page hit could have Link'ed assets pulled from the cache if present (if the client had previously visited that push-enabled resource (edit: in which case it's not the first I guess zzz). I guess the client, upon hitting a cached asset referenced in a Link header ignores it where otherwise it'd suck it down the socket as part of the same initial request.

Re:A Guide to HTTP/2 Server Push by EGreg on Monday April 10, 2017 @12:06PM (#14079672)
Push shouldn't be used for GETting things that you can cache. For that you can use pull with HTTP pipelining.

Push should only be used for updates, including updating the cache. Ideally you'd only be sending the deltas (changes).