46

I am using HTML5 Server-Sent Events as follows:

    SSEUpdate = new EventSource("http://example.com/update.php");
    SSEUpdate.onmessage = function(e){
      console.log(e.data);
    }

It does not work in IE11. (Error in console: 'EventSource' is undefined) Is there an identical Microsoft equivalent, or do I have to do something completely different?

GiantDuck
  • 1,086
  • 3
  • 14
  • 27

2 Answers2

82

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:

  1. 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 that do not support EventSource.
  2. Use instead - Although it requires more server-side setup (The ws:// protocol), it works in IE10 and 11 and provides more options such as bi-directional communication.
Mooseman
  • 18,763
  • 14
  • 70
  • 93
  • 2
    Has anyone had trouble with using IE10 and a polyfill where IE never closes the connection on tab/browser close? I have tried multiple polyfills and server implementations and it seems to be that IE's xhr.abort() will never close the connection :( – jCuga May 26 '15 at 14:48
  • 2
    How much longer do you think developers should continue to support IE? Even though a lot of people currently use it, it seems like a lot of trouble for something that is already deprecated. Should developers focus more on supporting Edge and other browsers that are here to stay? – www139 Dec 29 '15 at 03:45
  • @www139 Officially, Microsoft no longer supports IE. It really depends on your audience. If 0.001% of your users use IE, then there's no need to support. If 10% of your users use IE, then support is required, although you could allow your app to degrade gracefully (i.e., less eye candy but equal function). Any number between the two needs to be discussed further. – Mooseman Feb 04 '16 at 14:50
  • @Mooseman Thank you for your response. Here is one more question for you, how much longer do you think before the browser market share for IE is low enough (like 2-3%) that support could be dropped. It seems like market share is dropping rapidly from what I have seen. What do you think? – www139 Feb 06 '16 at 03:17
  • @www139 Current [world-wide usage is about 17%](http://gs.statcounter.com/#browser-ww-monthly-201501-201601-bar), and [USA usage is about 25%](http://gs.statcounter.com/#browser-US-monthly-201501-201601-bar). [IE8 is about 3% world-wide](http://gs.statcounter.com/#desktop-browser_version_partially_combined-ww-monthly-201501-201601-bar), but is only available on Windows 7 or older, so hopefully will be phasing out. Optimistically, I'd say 2-3 years, although having seen the battle against IE6, it may be much longer. At 3% though, it's more than safe to gracefully degrade in the browser. – Mooseman Feb 06 '16 at 23:15
  • 7
    For what it's worth, it's not just MS lacking this in IE, they've not got EventSource support in Edge either. What a crock. And as far as I'm concerned, I "have" to support Edge, because that's the default browser on Win10. – IanJ Feb 06 '17 at 15:57
  • @GiantDuck can you please tell me how you have used this in your project because i am getting error while using this . – Rohitesh Mar 31 '17 at 09:11
  • @Mooseman can you please let me know how we can use this i am using this like : const es = require('../../../style/vendors/EventSource'); es.EventSource('URL'); But, my connection is not getting established. – Rohitesh Mar 31 '17 at 09:17
  • @Rohitesh I would recommend opening a new question for that. Are you using Node.JS or RequireJS? – Mooseman Mar 31 '17 at 10:28
2

SSE native support for IE is not there. You can achieve same thing using polyfill

Prakash N D
  • 143
  • 2
  • 5