Explain what is Server-Sent Events (SSE) / EventSource?

Technology CommunityCategory: WebSocketsExplain what is Server-Sent Events (SSE) / EventSource?
VietMX Staff asked 3 years ago

Alongside with short and long polling, SSE is a technique for sending messages is the Server-Sent Events API, which allows the server to push updates to the client by leveraging the JavaScript EventSource. EventSource opens a persistent, one-directional connection with the server over HTTP using a special text/event-stream header and listens for messages, which are treated like JavaScript events by your code.

Server-Sent Events (SSE) are great for apps where you don’t need to send the server any data—for example, a Twitter-style news feed or a real-time dashboard of stock quotes. Another pro is that Server-Sent Events work over HTTP and the API is relatively easy to use.

However:

  • SSE is not supported by older browsers,
  • most browsers limit the number of SSE connections you can make at the same time.