What is the difference between WebSockets vs. Server-Sent events/EventSource?

Technology CommunityCategory: WebSocketsWhat is the difference between WebSockets vs. Server-Sent events/EventSource?
VietMX Staff asked 3 years ago

Websockets and SSE (Server Sent Events) are both capable of pushing data to browsers, however they are not competing technologies.

  • Websockets connections can both send data to the browser and receive data from the browser. A good example of an application that could use websockets is a chat application.
  • SSE connections can only push data to the browser. Online stock quotes, or twitters updating timeline or feed are good examples of an application that could benefit from SSE.

It can be overkill for some types of application to use WebSockets, and the backend could be easier to implement with a protocol such as SSE. Furthermore SSE can be polyfilled into older browsers that do not support it natively using just JavaScript.