# WebTransport

> The WebTransport is an API for low-latency, bidirectional client-server communication over HTTP/3.

## What is WebTransport and how is it different from WebSockets?

The API for exchanging data with a server over HTTP/3 using reliable streams and unreliable datagrams. Suits games, live streaming and other real-time apps where WebSocket over TCP adds too much latency.

- Topic: Data Transfer
- Type: technology

## Example

Wrong:

```js
const wt = new WebTransport('https://example.com/game');
const writer = wt.datagrams.writable.getWriter();
```

Right:

```js
if ('WebTransport' in window) {
  const wt = new WebTransport('https://example.com/game');
  await wt.ready;
  const writer = wt.datagrams.writable.getWriter();
} else {
  connectWebSocket('wss://example.com/game');
}
```

Feature detection adds a WebSocket fallback, and `await wt.ready` waits until the session is established.

## Common mistakes

- Sending important messages as datagrams and losing some of them.

## Key points

- Code checks for `WebTransport` support and falls back to WebSocket.
- The client awaits `transport.ready` and handles `transport.closed` errors.
- Datagrams are used only for data that may be lost, reliable data goes through streams.

## Interview questions

### What are datagrams in WebTransport?

Small messages sent without delivery or order guarantees. They suit frequently updated state like player positions, where old data is useless.

### Does WebTransport need a special server?

Yes. The server must support HTTP/3 and WebTransport sessions; a regular WebSocket server cannot accept these connections.

### Can WebTransport replace WebRTC?

Not for peer-to-peer media. WebTransport connects a client to a server, while WebRTC connects devices directly and handles audio and video.

## Related cards

- [HTTP/3](https://wonderium.dev/web/http-3.md)
- [QUIC](https://wonderium.dev/web/quic.md)
- [WebSocket](https://wonderium.dev/js/web-socket.md)
- [WebSocket](https://wonderium.dev/web/websocket.md)
- [WebRTC](https://wonderium.dev/web/webrtc.md)

---

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