How to do live updating similar to Google Docs? How to do live updating similar to Google Docs? ajax ajax

How to do live updating similar to Google Docs?


I vote for Long-poll strategy : each client opens a request to the server, but the server never breaks up connections, and just send pieces of java-script from time to time.

Constant AJAX requests would kill your server.


Check out google mobwrite. It's a drop-in library that enables collaborative editing of html forms via operational transformation.

Getting events pushed back from the server is the easy part, there are many ways to do it. Ensuring that the state is consistent across all clients, that's the hard part. That's where the operational transformation algorithm comes in.


A Ajax approach is one way to go. You could implement it like the chat applications. The actual way will depend on the data being view. In short

  1. Create a session. It could house the users sharing the doc (eg excel file)
  2. When user A make a change (eg. update cell A5), use Ajax to send the changes to the server. The change can be stored with the date of arrival or some index value.
  3. A background Ajax call is fired by the page from time to time. As part of the request, the last date of access is passed as well.
  4. Upon receiving the request, you simply serve all the changes made from the last time or index. You could include the new date or index value as part of the response so that it can be use for the next request.
  5. When you are sure that the top X elements will not be access, you could remove them

Whether it will be performance intensive or not will depend largely on how to structure everything.

Your other option is web sockets. Haven't used it personally but if you have control over what browser your users will use, you could give it a shot. It allows the server to push data to the browser.Some Links:Web Sockets JS and Web Sockets in Firefox