I have an asp.net MVC 4.0 application. In one of my views, I wish to display a list of current news (IEnumerable<News>
) coming from a Web API.
The thing is that the list of news may or may not be updated frequently. In other words, on an average day, the backend team may have to enter from 5 to 45 news using the backend CMS.
I need to figure out a way to refresh the user’s list of news within his browser without, of course, refreshing the entire web page.
My initial thought would have been to add a JavaScript setInterval()
method that would call the Web API every X milliseconds thus pulling the information and refreshing the list of news.
Although this would work, I would like to use a different approach and use SignalR
since I believe the requirement fits with what SignalR
has to offer.
After reading and looking at some examples on SignalR
, I’m starting to understand the idea behind it but I’m still a bit confused.
The examples I see are Chat rooms and games where users can click stuff which triggers a call to the hub
.
In my task, the user WILL NOT have anything to click. The hub
(server) should be responsible of calling the client every X milliseconds to update the list of news.
In terms of performance, it would be ridiculous to send the entire list of news at each X milliseconds and overwrite the UI.
I would need a way to compare the list of news currently showing in the user’s browser with the new list of news inside the hub. Once the compare is done, only send the new compared list of news.
Does anyone have any example of such a scenario or can give me some pointers on how to get this started?
Thanks