Search code examples
http2server-push

Can a HTTP/2 client choose which resources to receive via Server Push?


I have a static site. In order to speed up site loading, I want to push the CSS to the client using HTTP/2 Server Push. However, I am also concerned about bandwidth usage on mobile clients.

If I specify a resource to be pushed to the client (e.g. using http2_push <some file> in nginx) and the client already has this resource in their cache, can the client request the resource not to be pushed? Or does the server always push the resource?

I read RFC 7540, sec. 8.2 - HTTP/2 Server Push, but I only found that the client can send a RST_STREAM request to stop a server push. But is there a way the client can choose which resources they get pushed?


Solution

  • You can set a cookie and the server can use that to decide whether to push or not. I’ve an Apache implementation of that here: https://www.tunetheweb.com/performance/http2/http2-push/

    It’s not ideal as the cookie can be cleared independently of the cache but best we can do for now.

    Cache Digests was proposed as a solution to this problem, but work on this has stopped due to lack of interest — primarily due to concerns over privacy.

    HTTP/2 Push has failed to live up to expectations and can lead to performance degradation rather than improvements. Preloading through resource hints is cleaner and less risky. It can also be used with the 103 Early Hints status code - though support of that is not great either - see this Chrome issue for example.