Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single page apps keeping client and server in sync

I am trying to understand how single page apps spa's work.

My understanding of a spa is that you load the data on start-up and you use ajax calls for save etc, and the whole idea is that your models cache data on the client so you have a rich snappy experience in your browser.

I am confused as to how the client stays in sync with the server changes. E.G. If I have multiple users logged into my spa and they are all making changes, how does my client know that another user has updated a persons details if it is using cached data?

My guess is that something similar needs to happen server side to update the client on a change. Does this exist or am I misunderstanding something?

Any help or pointers to additional info would be much appreciated.

Thank you in advance.

like image 700
Mark Beattie Avatar asked Nov 13 '22 05:11

Mark Beattie


1 Answers

For server to client communication you can use SignalR.

SignalR allows you to create a hub on the server which you can then tell to update the clients.

It works with a fallback mechanism, it tries to use the following techniques and falls back onto the next one if it's not available in the browser:

  • Web Sockets
  • server sent events
  • forever frame
  • long polling

Link for fallbacks: http://www.asp.net/signalr/overview/introduction/transports-and-fallbacks

Link for signalR: http://signalr.net/

like image 141
Kenneth Avatar answered Nov 15 '22 11:11

Kenneth