On 12 August 2014 01:53, Edward Burns <edward.burns_at_oracle.com> wrote:
> If the server is going to pre-push resources that go along with
> a page, how can the server know if the user-agent already has an
> up-to-date copy of the resource in its cache? In the case where the
> user-agent already has the resource, pre-pushing it would be a waste of
> bandwidth.
>
Ed, this is a very important question!
How does http2 deal with this very fundamental problem?
>
Not at all!
In Jetty, we have implemented the heuristics based approach to build up a
push cache of related resources. Getting the framework involved (or just
delegating the entire responsibility to the framework) is going to allow
for better strategies because the framework should have more knowledge
about how pages are related. So this is where framework developers are
going to have to be smart to come up with
strategies and heuristics.
The Jetty heuristics are based on the referer and if-modified-since
headers. Firstly we work out which resources are related to each other
by tracking the referer headers for requests from the same session. If a
request is referred from another within a short timeout, then we assume it
is a closely associated resource and should be pushed.
Any request that has an if-modified-since header we assume is coming from a
client with a hot cache, or at least a warm cache, so we don't push any
resources at it. If the request doesn't have an if-modified-since header,
then we do push associated resources at it.
But there are a lot more smarts that could be done:
- how are query strings handled in associated requests? merged replaced?
ignored?
- should there be per session resource as well as per page resources
pushed?
But also note that from a transport point of view, pushing a resource can
be cancelled by the client if they have it already, so it does not use too
much bandwidth... but have to make sure we don't commit a server thread to
build something expensive that get's cancelled after sending 1 frame.
cheers
--
Greg Wilkins <gregw_at_intalio.com>
http://eclipse.org/jetty HTTP, SPDY, Websocket server and client that scales
http://www.webtide.com advice and support for jetty and cometd.