Javascript Starter Template

A simple Javascript starter template application for using

This template is a minimal application to get you started. Just replace the endpoint URL in the new EventSource(…) line with the SSE endpoint you want to use.

<!DOCTYPE html>
<html lang="en">
    <!-- Polyfill for older browsers without native support for the HTML5 EventSource API. -->
    <script src=""></script>
    <div id="payload"></div>

      const stream = new EventSource('');

      // Handler for when the stream is opened (either the first time or after a reconnect).
      stream.addEventListener('open', function(event) {
        console.log('Stream is open');
      }, false);

      // Handler for new messages.
      stream.addEventListener('message', event => {
        document.getElementById('payload').innerText =;
      }, false);

      // Handler for a dropped connection or the server closing the connection.
      stream.addEventListener('error', function(event) {
        switch ( {
            case EventSource.CONNECTING:
            case EventSource.CLOSED:
                console.log('Connection failed, will not reconnect');
      }, false);