2 ms·
Websockets would overkill for this kind of feature – you don't need realtime two-way communication. Server sent events (SSE) [1] are a much better alternative;
by simplify 10y ago
Websockets would overkill for this kind of feature – you don't need realtime two-way communication. Server sent events (SSE) [1] are a much better alternative; it's a simple, long-lived HTTP request where the server can push data to the client. They're built into most browsers [2], and the client-side polyfill [3] is small (2kb gzipped).
[1] https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events https://developer.mozilla.org/en-US/docs/Web/API/Server-sent...
[2] http://caniuse.com/#search=server-sent%20events http://caniuse.com/#search=server-sent%20events
[3] https://github.com/Yaffle/EventSource https://github.com/Yaffle/EventSource
- nevi-me 10y agoFair enough, but what happens if I open a page, send an Ajax call to say "add 1 user", then promptly close that page? I don't know what OP is doing to detect that a user is no longer on the site. The reasons why I used WebSockets are that I get a disconnect event immediately, and I was already using WebSockets for other features on the site
- simplify 10y agoIt's a long-lived HTTP request. The server automatically knows if a client disconnects; that's a feature built into all HTTP server libraries everywhere. But yes, if you're already using websockets for other features, there's no reason not to continue to use them, as you explained :)