It seems in both cases client sends a request to server and server answers, unless in server sent event you can set retry time in your server side code. So is there any benefit in using SSE rather than jQuery post or get method?
Obviously, the major difference between WebSockets and Server-Sent Events is that WebSockets are bidirectional (allowing communication between the client and the server) while SSEs are mono-directional (only allowing the client to receive data from the server).
Long-polling opens an HTTP request and remains open until an update is received. Upon receiving an update, a new request is immediately opened awaiting the next update. Server-sent events(SSE) rely on a long-lived HTTP connection, where updates are continuously sent to the client.
WebSockets generally do not use 'XMLHttpRequest', and as such, headers are not sent every-time we need to get more information from the server. This, in turn, reduces the expensive data loads being sent to the server. WebSocket connections can both send and receive data from the browser.
SSE is commonly used to send message updates or continuous data streams to a browser client. In a nutshell, a server-sent event is when updates are pushed (rather than pulled, or requested) from a server to a browser.
SSE is not supported by IE but you can make it work with IE 8+ if you use a library.
Server sent events create less traffic on the server. The client does not need to ask for news every minute. Data is only delivered when it is available. Also the data arrives instantly at the client not only when the client ask for it.
If you like to use SSE you should use a library like Yaffle's EventSource.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With