Reputation: 2609
Recently I've found out of Server-Sent events as a much simpler alternative to WebSockets for doing push from the server. Most places that compare them (like here, here and here) say that if you don't need full duplex communications between client and server, then WebSockets is overkill and SSE are good enough.
My question is what would be the downside of using SSE when you do need bidirectional communications (like a chat for example), using regular ajax requests for sending messages from the client and the server stream for receiving them? Considering that I have to do little to no configuration on the server side to use SSE, it seems to be a much more appealing option.
Upvotes: 20
Views: 10587
Reputation: 73215
SSE Advantages over WebSockets:
SSE Disadvantages compared to WebSockets:
References:
Upvotes: 31
Reputation: 129075
Ajax requests are huge compared to small WebSocket messages. Standard HTTP requests (Ajax) include a lot of headers including cookies with every request while WebSocket messages is just a few bytes.
The good thing with HTTP (Ajax) request is that they are easier to cache if that is a benefit for your problem.
Upvotes: 3