Does the browser cancel server push when a resource is in cache?
Asked Answered
C

2

32

The HTTP/2 specification indicates that any resource identified in a PUSH_PROMISE frame won't be pushed if the client cancels it.

When a browser detects a resource already in the cache, it should cancel the push for this resource. However, I don't see how the browser can detect it. Do the frames provide additional informations like etag or last modified to allow the browser to detect if any cache entry must be evicted or if the push could be canceled?

If it's possible, some bandwidth could be saved. However, it seems server-push compromises any client cache optimization.

Chrystalchryste answered 30/3, 2015 at 17:16 Comment(0)
C
50

In HTTP/2 the server pushes to the client a request for the resource with a PUSH_PROMISE frame.

While going from server to client, this is not a response, but a request, the request the client would make to fetch that resource.

When the client receives the PUSH_PROMISE, it can look at the URI, and figure out the cache status of this resource. Browsers typically use different caches for normally received resources and pushed resources. If the cache is still valid, the client may cancel the pushed stream by sending a RST_STREAM frame to the server for that stream.

Meanwhile, the server starts what it takes to push the resource. This will generate a HEADERS response frame that will contain the typical response headers such as etag. When the client receives the HEADERS response frame, it has one more chance to cancel the stream, although - of course - DATA frames may be inflight, possibly all of them.

Saving bandwidth may be interesting, but it's typically not a problem to waste a little bandwidth; what matters more from the user experience point of view is the latency, and the push mechanism reduces that by a considerable amount.

I don't think the push mechanism compromises any client cache optimization; had this been the case, browser vendors would have fought against this feature, while instead most of them (if not all) implement it with very good results in user experience and diminished latency.

Sure the mechanism could be improved, for example by having clients and servers agree on some header that will give more information about the resource being pushed, but so far works fairly well.

[Disclaimer: I'm a Jetty committer] Having been the first to implement SPDY and HTTP/2 Push for the Java ecosystem (almost 3 years ago), the Jetty Project is certainly interested in more discussions and ideas around HTTP/2 Push.

Chemarin answered 30/3, 2015 at 19:0 Comment(2)
I'm curious if you know what mechanic the client uses to know if it can cancel the push. Is an etag or last modified or something sent with the push promise? This Chromum page about SPDY seems to indicate that a PUSH would be redundant (ignore cache) and a HINT would ask the browser to fetch the item, after checking its cache: chromium.org/spdy/link-headers-and-server-hint Did this mechanic change between SPDY and HTTP2?Arbuthnot
In addition to my above comment, there is a Chrome discussion thread here groups.google.com/a/chromium.org/forum/#!msg/net-dev/… (more specific to SPDY) that indicates that there is no support for server push caching. Server pushed files from an HTTP2 server do not show up in chrome://cache (the originally requested file does appear in cache, but additionally pushed files do not). I'm thinking the HTTP2 spec could let a browser receive an etag in the PUSH_PROMISE and cancel the push, but it looks like Chrome, at least, is not implemented that way.Arbuthnot
A
5

Simple and short answer: Yes, browser will cancel server push if it has this URL in cache.

Abutment answered 19/11, 2015 at 8:55 Comment(3)
Any sources for this? This article disagrees css-tricks.com/cache-aware-server-pushExact
From that article: Browsers do have the capability to reject pushes. However, by the time it's rejected much or all of the file may already have been transmitted due to latency. The article goes further into how you can reduce the wasted bandwidth when a client is likely to have the resource already cached.Cain
So why Nginx here nginx.com/blog/nginx-1-13-9-http2-server-push is explaining how to use a cookie to not send content that the browser already have?Tireless

© 2022 - 2024 — McMap. All rights reserved.