O'Reilly logo

Data Push Apps with HTML5 SSE by Darren Cook

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Fallbacks: There Has to Be a Better Way!

In the previous chapter we looked at long-poll as a way to push data from server to clients that do not support SSE. Its advantage over SSE is that it works just about everywhere, and its disadvantage is that the slightly higher latency and slightly higher bandwidth use can become significant for high-frequency updates. In this chapter we will look at two alternatives that are almost as good as native SSE, from the latency and bandwidth point of view.

The first fallback we look at uses Ajax, just as long-poll did, but using readyState == 3, instead of readyState == 4. In a nutshell it means we get each piece of data as the server pushes it out, while the connection is still alive, in contrast to long-poll where we don’t see any of the data until the server closes the connection. (If you skipped over the sidebar Ajax readyState, this might be a fine time to go back and review what the Ajax readyState values mean.)

This is a nice approach, only slightly less efficient than SSE, so it is ironic that it gives us hardly any more desktop browser coverage.[29] Why? Because most of the browsers where it works already have native SSE support! However, this technique does work in Android 4.x (representing about two-thirds of Android users at the time of writing).

The second fallback is specifically for Internet Explorer 8 and above. There is nothing particularly IE-specific in the technique, so it is strange that it either does not work, or ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required