How to design a multi-user ajax web application to be concurrently safe

前端 未结 8 1140
梦谈多话
梦谈多话 2021-01-29 16:59

I have a web page that shows a large amount of data from the server. The communication is done via ajax.

Every time the user interacts and changes this data (Say user A

相关标签:
8条回答
  • 2021-01-29 17:45

    Server-side push techniques are the way to go here. Comet is (or was?) a buzz word.

    The particular direction you take depends heavily on your server stack, and how flexible you/it is. If you can, I would take a look at socket.io, which provides a cross-browser implementation of websockets, which provide a very streamline way to have bidirectional communication with the server, allowing the server to push updates to the clients.

    In particular, see this demonstration by the library's author, which demonstrates almost exactly the situation you describe.

    0 讨论(0)
  • 2021-01-29 17:46

    Trying to write all this yourself is a big job, and it's very difficult to get it right. One option is to use a framework that's built to keep clients in sync with the database, and with each other, in realtime.

    I've found that the Meteor framework does this well (http://docs.meteor.com/#reactivity).

    "Meteor embraces the concept of reactive programming. This means that you can write your code in a simple imperative style, and the result will be automatically recalculated whenever data changes that your code depends on."

    "This simple pattern (reactive computation + reactive data source) has wide applicability. The programmer is saved from writing unsubscribe/resubscribe calls and making sure they are called at the right time, eliminating whole classes of data propagation code which would otherwise clog up your application with error-prone logic."

    0 讨论(0)
提交回复
热议问题