HTTP/2 Server Push lets us send responses to requests that haven't been made yet. The client will cache those, and when the request is finally issued, the response will be taken from the cache, speeding everything up. This is useful for stuff we know the user will need, like CSS and some images.
It's an open question on how to figure out that the client actually needs the resources. We obviously don't want to push CSS every time—we shouldn't waste the bandwidth of returning visitors like that.
I'd prefer not to set cookies.
As an alternative, I can rely on two Nginx variables:
$ssl_session_reused. The fact that a session was reused indicates that this is a returning visitor. Hopefully they still have the cache of our earlier responses. Don't push anything;
$connection_requests. If this equals 1, this is the first request of the connection. It's likely that the user doesn't yet have anything in their cache.
Obviously, I should only push stuff if the request asks for HTML files; do not push stuff to people who request RSS feeds, images, etc.
We can also check of presence of ETag and If-Modified-Since headers. If both are absent, the client probably doesn't have a cache of our resources yet, so we should push them.
HTTP/2 Server Push lets us send responses to requests that haven't been made yet. The client will cache those, and when the request is finally issued, the response will be taken from the cache, speeding everything up. This is useful for stuff we know the user will need, like CSS and some images.
This can be done with
http2_push
Nginx directive, supported since Nginx 1.13.9. Here's a primer on Server Push with Nginx.It's an open question on how to figure out that the client actually needs the resources. We obviously don't want to push CSS every time—we shouldn't waste the bandwidth of returning visitors like that.
I'd prefer not to set cookies.
As an alternative, I can rely on two Nginx variables:
$ssl_session_reused
. The fact that a session was reused indicates that this is a returning visitor. Hopefully they still have the cache of our earlier responses. Don't push anything;$connection_requests
. If this equals 1, this is the first request of the connection. It's likely that the user doesn't yet have anything in their cache.Obviously, I should only push stuff if the request asks for HTML files; do not push stuff to people who request RSS feeds, images, etc.