Sunday, May 10, 2020

Tip: How to use HTML5 Server Side Events

Server Side Events (SSE) allows the web server (node.js, IIS, Apache, etc) to keep a connection active with the client browser while server is pushing data to the client whenever needed. However SSE is not the same as WebSockets as it can only push data from server whereas WebSockets can both receive and push data. Below is a very simple SSE application developed using node.js and HTML.


Server Code



Client Code

You can include the following snippet in the html header section
You will receive the following in Chrome debugger if the message is sent successfully from the server.