Sobes.tech
Middle

What are the differences between HTTP/1 and HTTP/2 protocols?

sobes.tech AI

Answer from AI

Main differences between HTTP/1.1 and HTTP/2:

  • Multiplexing:

    • HTTP/1.1: Sequential processing of requests over one connection. Multiple TCP connections were required for parallel loading.
    • HTTP/2: Multiplexing over a single TCP connection. Allows sending multiple requests and receiving responses simultaneously without blocking each other.
  • Header compression (HPACK):

    • HTTP/1.1: Headers are transmitted uncompressed, which can be redundant with many requests.
    • HTTP/2: Header compression using the HPACK algorithm. Reduces the size of transmitted data.
  • Stream prioritization:

    • HTTP/1.1: No prioritization capability.
    • HTTP/2: Clients can assign priorities to different data streams, influencing their processing order on the server.
  • Server Push:

    • HTTP/1.1: Clients must explicitly request each resource (CSS, JS, images).
    • HTTP/2: Server can proactively send resources it anticipates the client will need to display the page, before the client requests them.
  • Binary protocol:

    • HTTP/1.1: Text-based protocol, relatively easy to read.
    • HTTP/2: Binary protocol, more efficient for parsing and transmission.

Comparison table:

Characteristic HTTP/1.1 HTTP/2
Multiplexing No (requires multiple TCP) Yes (single TCP)
Header compression No Yes (HPACK)
Stream prioritization No Yes
Server push No Yes
Protocol format Text Binary
Head-of-Line blocking issue Present (for one TCP) Reduced thanks to multiplexing

Conceptual example of multiplexing:

// HTTP/1.1: Sequential requests
fetch('/resource1')
  .then(() => fetch('/resource2'))
  .then(() => fetch('/resource3'));

// HTTP/2: Parallel requests over one connection
// In browsers, this happens automatically for HTTP/2
// Requests can be sent almost simultaneously