Minoru / blog.tty8.org

Source code for my blog
https://blog.tty8.org
9 stars 1 forks source link

Push resources to all new connections #42

Open Minoru opened 4 years ago

Minoru commented 4 years ago

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:

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.

Minoru commented 4 years ago

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.