In this tutorial I want to show you how server-side events can be implemented in Dotnet Core and JavaScript in a library-free fashion.

In modern web development seeing data on websites update in realtime is very common. Look for example at the courier on the map of your Takeaway order or at the ETA on a track-and-trace page for the delivery of your new shoes. That is (most-likely) all live data, coming directly from the server to your screen.

There are various ways you can implement such features. With Dotnet Core you can of course use SignalR, but if you just want to live update an ETA this is a pretty big and relatively complicated hammer for a small problem. On the other end of the spectrum you could use a client-side loop that gets a new value every X seconds from a normal REST endpoint. While this is a very simple solution, it also isn’t really realtime (with a sensible interval at least).

A third, less-known, solution is to use a server-side event stream. Server-side events allow you do send realtime events to a client, are supported by plain JavaScript and can be done with just a normal action in a standard controller. This gives them the potential to sit nicely in-between the two earlier mentioned options.

#typescript #web-development #javascript #dotnet

Server-side Event Streams with Dotnet Core and TypeScript
3.15 GEEK