DEV Community

Rizwan Saleem
Rizwan Saleem

Posted on

HTTP/2 and HTTP/3: what they bring and how to leverage them

HTTP/2 and HTTP/3: what they bring and how to leverage them

HTTP/2 and HTTP/3 are major revisions of the HTTP protocol that bring significant performance improvements. Understanding their features helps you optimize your applications for the modern web.

HTTP/2 introduced multiplexing, which allows multiple requests to share a single TCP connection. This eliminates head-of-line blocking where one slow request blocks others. HTTP/2 also supports server push, header compression, and binary framing. Enabling HTTP/2 on your server is usually a configuration change away.

HTTP/3 uses QUIC, which is built on UDP instead of TCP. QUIC solves TCP-level head-of-line blocking if one packet is lost, only that stream is blocked while others continue. QUIC also reduces connection establishment time from 3 round trips to 1. HTTP/3 is especially beneficial for mobile users with unreliable connections.

Enable HTTP/2 on your server. Most web servers and CDNs support it with a simple configuration change. NGINX, Apache, and most cloud load balancers support HTTP/2. The performance improvement is significant, especially for sites that load many assets.

Server push in HTTP/2 lets the server send resources before the client requests them. If the client requests an HTML page, the server can push the CSS and JavaScript files it knows will be needed. However, server push is tricky to get right pushing resources the client already has cached wastes bandwidth.

Optimize for multiplexing. HTTP/2 multiplexing makes domain sharding unnecessary serving assets from one connection is faster than spreading them across multiple domains. Concatenation of CSS and JavaScript files also becomes less important since multiple small files can be served efficiently.

Measure the impact of protocol upgrades. Test with and without HTTP/2 and HTTP/3 using Lighthouse and WebPageTest. The improvements vary by application type and user location. Server-side improvements from HTTP/2 are most noticeable on sites with many assets.

-

Rizwan Saleem | https://rizwansaleem.co

Top comments (0)