DEV Community

Discussion on: Event Source Interface, an unidirectional alternative to Sockets in JavaScript

Collapse
diegomgar profile image
Dieg Oto

I don't really understand the difference between doing this and request a GET to retrieve that data using a recursive timeout. Can you extend this?
Thank you.

Collapse
felipperegazio profile image
Felippe Regazio Author • Edited

I can see some benefits to not Polling (your suggestion) depending on your needing:

  1. Performance. You can create a new request like a heartbeat and keeps asking data to the server, consuming extra memory, while with SSE (Server Sent Events, or the EventSource), the server pokes your app and say "heres new data".

  2. Provides a pattern. If you use the javascript EventSource API your code will be easier to understand considering new devs on the base and the already-made online docs.

  3. Polling is not always a good option. Imagine a very long task on server, it could lead to timeouts on both sides (server timeouts and client timeouts), with the proper protocol or interface, this wouldn't happen.

I could say some things more but i believe that really depends of your use case. This article is a good source to discover the differences between Polling, SSE and Sockets deeply:

codeburst.io/polling-vs-sse-vs-web...