SignalR vs setTimeout

Part of my MVC view page is updated every 30 seconds after receiving some resource from the server. I used setTimeOut to run the javascript method to asynchronously retrieve data from the server, compare it with old data, and if it has changed, update the div tag. Now I'm going to create a timer in the global.asax class, start it in the application_start event and in the last time event, get the data and send it to all clients using SignalR only if the data has been changed.

Will there be any advantage to using SignalR over setTimeOut here?

+4
source share
1 answer

The advantage in this case would be that you would avoid an unnecessary trip to the server if this data has not changed. Using SignalR, you can transfer data to all clients only when the data has been changed.

Another advantage is that SignalR will migrate from the server to the browser using the best available technologies, without having to worry about it. This can be WebSockets if you are using a server on a server running Windows 8 using ASP.NET 4.5 (possibly in the future) or Server Sent Events if the client is Chrome, Firefox or Opera or Forever Frame, if the client is IE. In any case, you do not need to worry about this, SignalR will take care of transport management for you.

Depending on where your data is stored and how it is updated, you can even completely disable the timer and simply transfer data to all clients immediately after changing it. If it is updated by another method of action on the controller, simply pass it on to customers. If it is updated through some other process directly in the database, you can configure the notification of the SQL query in your application (in App_Start) to receive a warning when it has been changed and then transmitted at this point.

+5
source

Source: https://habr.com/ru/post/1385561/


All Articles