What the difference between `onmessage` and `.addEventListener`?

source.onmessage is the built in function wrapper for EventSource that is triggered when new data is sent to the client. It fires when no event attribute is returned (default) and doesn’t fire when it is set. addEventListener is similar, but differs in that it listens for a specific event name, and triggers on its presence, … Read more

cURL – Structuring request to validate server sent events

SSE is a text-based protocol, and curl is a great way to troubleshoot exactly what your connection is sending. The command is this simple: curl -N http://127.0.0.1/path/to/clock.php (The -N stops any buffering, so data is shown as it is received.) And it outputs this: data:2015-07-07 06:19:27 data:2015-07-07 06:19:28 data:2015-07-07 06:19:29 data:2015-07-07 06:19:30 data:2015-07-07 06:19:31 data:2015-07-07 … Read more

What is the difference between Push API and Server Sent Events?

The Push API allows the server to send a notification to a client even when your site is not open, because it relies on service workers. SSE (or WebSockets) work as long as the user is using your site. There are some examples (with documentation) in the Web Push section of the ServiceWorker Cookbook that … Read more

Is there a Microsoft equivalent for HTML5 Server-Sent Events?

In a word, no. Microsoft has not included SSE or an equivalent of SSE in any version of IE. IMO, you have two good options: Use a polyfill – My tests with this polyfill in IE10 and IE11 were all successful. Since it starts with if (“EventSource” in global) return;, it’ll only run in browsers … Read more

Is an EventSource (SSE) supposed to try to reconnect indefinitely?

Server Side Events work differently in all of the browsers, but they all close the connection during certain circumstances. Chrome, for example, closes the connection on 502 errors while a server is restarted. So, it is best to use a keep-alive as others suggest or reconnect on every error. Keep-alive only reconnects at a specified … Read more

What technology does Google Drive use to get real-time updates?

Is there a name for Google’s solution for real-time updates in Drive (such as “long polling” or “sockets”)? It didn’t have a name until now. I’ll call it “no-polling,” to contrast with polling and long-polling. With polling, the client periodically sends queries for new data. With long-polling, the client queries for data, and the server … Read more

Server-Sent Events vs Polling

Ajax polling adds a lot of HTTP overhead since it is constantly establishing and tearing down HTTP connections. As HTML5 Rocks puts it “Server-Sent Events on the other hand, have been designed from the ground up to be efficient.” Server-sent events open a single long-lived HTTP connection. The server then unidirectionally sends data when it … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)