Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

http2 - Does the browser cancel server push when a resource is in cache?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...