Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push resources to all new connections #42

Open
Minoru opened this issue Jul 27, 2020 · 1 comment
Open

Push resources to all new connections #42

Minoru opened this issue Jul 27, 2020 · 1 comment

Comments

@Minoru
Copy link
Owner

Minoru commented Jul 27, 2020

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.

@Minoru
Copy link
Owner Author

Minoru commented Aug 4, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant