Using HTML5 Server-Sent Events in a web application

To use Server-Sent Events in a web application, you would need to add an <eventsource> element to the document.

The src attribute of the <eventsource> element should point to an URL that should provide a persistent HTTP connection that sends a data stream containing the events.

The URL would point to a PHP, PERL or any Python script that would take care of sending event data consistently.


Here is an example showing application that would expect server time.

         /* Define event handling logic here */

      <div id = "sse">
         <eventsource src = "/cgi-bin/ticker.cgi" />
      <div id = "ticker">

Updated on: 20-Dec-2019


Kickstart Your Career

Get certified by completing the course

Get Started