Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery and AJAX or server sent events

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?

like image 940
Rsh Avatar asked Oct 12 '11 11:10

Rsh


People also ask

What is the difference between server-sent events SSEs and WebSockets in html5?

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).

What are the differences between long polling WebSockets and server-sent events?

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.

Why use server-sent events over WebSockets?

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.

What are server-sent events used for?

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.


1 Answers

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.

like image 191
PiTheNumber Avatar answered Nov 15 '22 21:11

PiTheNumber