title: Is an EventSource (SSE) supposed to try to reconnect indefinitely?
body: <p>I'm working on a project utilizing Server-Sent-Events and have just run into something interesting: connection loss is handled differently between Chrome and Firefox.</p>
  
  <p>On Chrome 35 or Opera 22, if you lose your connection to the server, it will try to reconnect indefinitely every few seconds until it succeeds. On Firefox 30, on the other hand, it will only try once and then you have to either refresh the page or handle the error event raised and manually reconnect.</p>
  
  <p>I much prefer the way Chrome or Opera does it, but reading <a href="http://www.w3.org/TR/2012/WD-eventsource-20120426/#processing-model" rel="noreferrer">http://www.w3.org/TR/2012/WD-eventsource-20120426/#processing-model</a>, it seems as though once the EventSource tries to reconnect and fails due to a network error or other, it shouldn't retry the connection. Not sure if I'm understanding the spec correctly, though.</p>
  
  <p>I was set on requiring Firefox to users, mostly based on the fact that you can't have multiple tabs with an event stream from the same URL open on Chrome, but this new finding would probably be more of an issue. Although, if Firefox behaves according to spec then I might as well work around it somehow.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I'm going to keep targeting Firefox for now. This is how I'm handling reconnections:</p>
  
  <pre><code>var es = null;
  function initES() {
      if (es == null || es.readyState == 2) { // this is probably not necessary.
          es = new EventSource('/push');
          es.onerror = function(e) {
              if (es.readyState == 2) {
                  setTimeout(initES, 5000);
              }
          };
          //all event listeners should go here.
      }
  }
  initES();
  </code></pre>