# HTTP/2

> The HTTP/2 is the second major version of the HTTP protocol that uses multiplexing over a single connection.

## What is HTTP/2 and how is it faster than HTTP/1?

The version of HTTP that transfers data in binary frames and multiplexes many requests over a single TCP connection. Also compresses headers with HPACK, which makes splitting code into many small files much cheaper.

- Topic: Communication Protocols
- Type: protocol

## Example

Wrong:

```nginx
server {
  listen 80 http2;
  server_name example.com;
}
```

Right:

```nginx
server {
  listen 443 ssl;
  http2 on;
  server_name example.com;
}
```

Browsers only use HTTP/2 over TLS, so it has to be enabled on the HTTPS listener, not on port 80.

## Common mistakes

- Splitting assets across many domains, which breaks connection reuse.

## Key points

- Old HTTP/1 tricks like domain sharding and huge bundles are not added only to reduce request count.
- Code does not rely on HTTP/2 server push, which browsers have removed.
- The server enables HTTP/2 over TLS, since browsers do not use it over plain HTTP.

## Interview questions

### Is HTTP/2 server push still supported?

No, major browsers removed it. Use `103 Early Hints` or `<link rel="preload">` instead.

### Do I still need to bundle files with HTTP/2?

Less than before. Many small files are cheap, but thousands of modules still add overhead, so moderate bundling with code splitting works best.

### How do I check if a site uses HTTP/2?

Open the Network panel in DevTools and enable the Protocol column; HTTP/2 requests show 'h2'.

## Related cards

- [HTTP/3](https://wonderium.dev/web/http-3.md)
- [HTTP](https://wonderium.dev/web/http.md)
- [TCP](https://wonderium.dev/web/tcp.md)
- [TLS](https://wonderium.dev/web/tls.md)
- [QUIC](https://wonderium.dev/web/quic.md)

---

- Level: [Web Platform](https://wonderium.dev/web.md)
- HTML version: https://wonderium.dev/web/http-2
- Last updated: 2026-11-25
