One benefit of http2 is that it can multiplex all communication over a single TCP connection. So when establishing a websocket connection the browser has to open a new tcp connection and negotiate TLS again. I wish they got on and added websocket support to http2 so a websocket request could piggyback off the socket used to download the other resources on the page in the first place.
Websockets are meant to be somewhat long lived. I don't think it would ideal to push websockets communication over HTTP2, it would significantly complicate the HTTP2 standard (what goes first, a websocket packet or http response? How do you differentiate? What about multiple sockets?)
The tls handshake cost is ultimately peanuts for connections that are supposed to live > 10 seconds. It only matters when you are talking about many short lived connections, which defeats the purpose of websockets.
2
u/sephg Jun 13 '19
One benefit of http2 is that it can multiplex all communication over a single TCP connection. So when establishing a websocket connection the browser has to open a new tcp connection and negotiate TLS again. I wish they got on and added websocket support to http2 so a websocket request could piggyback off the socket used to download the other resources on the page in the first place.