HTML5 Server Sent Events

HTML5 introduces a lot of new methods to communicate with other services. Web Sockets are a great example of this, however, using them can be fairly complicated. The Server-Sent Events specification defines a way to trigger DOM events using an active HTTP connection.

Feature Detection

This example opens an Event Stream with a simple PHP script, which outputs links to a random XKCD comic every 50 to 2500 milliseconds.

EventSource Interface
fail
<event-source>
fail

Random XKCD Comics

Source for the server-side PHP script is available, as well as a list of XKCD comics. This example won't run longer than 30 seconds.