Skip navigation.

Log in | Sign up

Opera Core Concerns

Official blog for Core developers at Opera

The long journey of Server-Sent Events (EventSource)

, ,

Over six years ago Ian Hickson wrote up a proposal for Server-sent DOM events. This feature allowed for creating a persistent connection with the server over HTTP and let it stream updates to the page as DOM events. News tickers, stock updates, and all kinds of other use cases would be a lot easier to implement. It became part of something that is now known as HTML5 and we prototyped an implementation and shipped it in Opera 9.

The specification however was really quite complex and our implementation not entirely complete. Based on feedback from Jonas Sicking the feature was redesigned to no longer be based on an element, but rather a simple object — much like XMLHttpRequest. Feedback before that had already drastically simplified the event stream format so no longer each and every feature of a DOM event had to be supported. The EventSource object also moved out of HTML5 into its own Server-Sent Events specification.

When WebKit gained an implementation of this feature we thought we should update our experimental version so less special casing by developers would be needed. I wrote a test suite for EventSource and Pablo Flouret then went to update our implementation which resulted in quite a bit of code removal :hat: (We love code removal.) Our work can be found in the latest Opera 10.70 snapshot and will most certainly make it into Opera 10.70 final as well. The test suite will be contributed to the W3C WebApps WG and has already been shared with WebKit developers.

Now we have two implementations — i.e. one in Opera and one in WebKit — that are very close to each other and six years of experience with the feature, the Server-Sent Events specification can finally become a standard. :beer:

WebSockets in Opera


Charles Schloss 11. October 2010, 14:54


BS-Harou 11. October 2010, 16:37

For me are "Server-Sent Events" much more interesting than Web Sockets and working with it is much easier.

Thank you for your hard work and for adding Function.prototype.bind! :yes:

BS-Harou 11. October 2010, 17:32

btw can you please give here content of "resources/message.php" ? =)

I was trying to create something by myslef, but it gives me the same message every second and I don't know how to stop it)

This is what I have in my php file:
header("content-type: text/event-stream; charset: utf-8");
header("Cache-Control: no-cache");
data: test
id: 1

d4rkn1ght 11. October 2010, 17:43


Anne van Kesteren 12. October 2010, 12:01

BS-Harou, you can get the raw code via Subversion:

It gives you the same message because it keeps reopening the connection. To close the connection the server has to give a special status code or the client has to invoke close() on the EventSource object.

BS-Harou 12. October 2010, 14:10

Originally posted by anne:

BS-Harou, you can get the raw code via Subversion:

Thank you very much I'm a bit smarter again =)

Anyway, there is still one thing I don't fully understand. Why is in the spec. this:
"When a user agent is to reestablish the connection, ..., queue a task to fire a simple event named error at the EventSource object"

Why it should fire the error event? What is the error?

btw I think that there should be some special property on the error event object with better description of error(s). That will help a lot with developing and catching errors.

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.