0

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?

Community
  • 1
  • 1
iblue
  • 29,609
  • 19
  • 89
  • 128
  • StackOverflow also shows this as related: https://stackoverflow.com/questions/29352282/does-the-browser-cancel-server-push-when-a-resource-is-in-cache – iblue May 08 '20 at 12:18

1 Answers1

1

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.

Community
  • 1
  • 1
Barry Pollard
  • 40,655
  • 7
  • 76
  • 92
  • We cannot set a cookie before the user has made their settings in the GDPR cookie consent form. But by then, the site has already rendered. So I think, I will go with a `Link` header instead of push, that way at least the browser can load the fonts before the stylesheet is loaded. – iblue May 08 '20 at 12:26
  • Well any other way of informing the user about the status of the cache would fall foul of GDPR for the same reasons! GDPR is not just about cookies (and neither is the ePrivacy directive) though most examples use them. So yeah `Link` header is your best option. – Barry Pollard May 08 '20 at 12:29
  • 1
    Though it could be argued that not re-pushing the same resource based on a cookie is a progressive enhancement (it’s not like the site breaks with over pushing) so that’s the OK for those that don’t accept cookies. It’s a fine line though as to whether you are “enhancing” the experience for those that accept cookies with functionality that is simply not available without cookies, but which is not critical to using the site (which is allowed) or “penalising” those that don’t accept cookies in an effort to force them into accepting them (which is definitely not allowed). – Barry Pollard May 08 '20 at 12:35