WebSockets.
One phone call that never hangs up, so the server can finally speak first.
Refreshing a chat page to see if your friend has replied yet is the web working exactly as designed. HTTP only speaks when spoken to: the browser asks, the server answers, the connection closes. The server might have news for you one second later and no way at all to say so.
A WebSocket fixes the rudest part of that arrangement. One ordinary request asks the server to keep the line open, and from then on both sides share a single connection where either can talk whenever it likes. The server stops being a vending machine and becomes the other end of a call.
- Us again. Same question.1
Every plain-HTTP exchange pays the full setup cost again, and only the asker may ever start one.
- 2
The opening move is still a normal request, carrying one extra ask: keep this line after you answer.
- 3
From here on there is no ask-then-answer choreography; either end sends the moment it has something.
- It texted first. Unheard of.4
News now travels when it exists, not when somebody finally thinks to ask for it.
- 5
Anything where half a second of lag reads as broken leans on this: typing dots, game state, tickers.
- 6
Open lines die quietly (trains hit tunnels, laptops nap), so real apps heartbeat and redial on their own.
The old workaround was nagging
Before WebSockets, a “live” page just asked over and over: any news? any news? Poll every five seconds and the auction you are watching ends between two of your questions; poll every 200 milliseconds and you bury the server in thousands of nos for every yes. Push inverts the economics — silence costs nothing, and news arrives the instant it exists.
An open line is a kept promise
Holding a connection per user is real work: ten thousand viewers means ten thousand lines the server keeps in memory, pings with heartbeats, and mourns when they vanish mid-word. And vanish they do, constantly, because phones hop networks and laptops shut their lids. Production WebSocket code is mostly reconnection code.
So the dividing line is who has news. If data only changes when the user acts, plain requests stay simpler. Reach for the open line when the server has things to say on its own schedule.