How to do live updating similar to Google Docs?

2020-05-12 04:53发布

I want to do something very similar to Google Doc's live updating - where all users can "immediately" see the actions of the other users in the doc.

To achieve this, my ideas so far:

  • Continuous AJAX requests being done in the background (this would seem performance-intensive)?
  • Surely there's not a way for the server to push notifications to all its clients and update them accordingly?
  • AJAX requests every X seconds with a buffer/time-lapse of actions to be accomplished in those X seconds (simulating a real-time effect)?

I would like to know others experience in trying to achieve this effect. What is the best way to do this?

All help is appreciated.

NOTE: I'm not specifically looking for a real-time document editing solution. I'm looking for a solution to the same concept of what Google does with their Docs. I will actually be using that solution in a slightly different manner.

11条回答
放荡不羁爱自由
2楼-- · 2020-05-12 05:43

Also take a look at pubsubhubbub - http://code.google.com/p/pubsubhubbub/ Watch the video for a short intro.

查看更多
我想做一个坏孩纸
3楼-- · 2020-05-12 05:44

Another alternative is Orbited:

Orbited provides a pure JavaScript/HTML socket in the browser. It is a web router and firewall that allows you to integrate web applications with arbitrary back-end systems. You can implement any network protocol in the browser—without resorting to plugins.

Orbited is an HTTP daemon that is optimized for long-lasting comet connections. It is designed to be easily integrated with new and existing applications. Orbited allows you to write real-time web applications, such as a chat room or instant messaging client, without using any external plugins like Flash or Java.

查看更多
Anthone
4楼-- · 2020-05-12 05:44

One way to limit the # of ajax requests is to get clever with spacing them out. You don't need to make a request every second. When you get a response with activity, then do another request in 1 second. If no activity, then 2 seconds, then 4, etc, with maximum of maybe 30 seconds in between requests. When updates happen, reset the timer. Basically, space your requests in a smart way to make the GUI look as responsive as possible.

查看更多
我想做一个坏孩纸
5楼-- · 2020-05-12 05:46

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.

查看更多
贼婆χ
6楼-- · 2020-05-12 05:47

You could also have a look at ShareJS a Operational Transform libary and Derby which is a framework built on sharejs. They both have node.js backends - sharejs was written by a Google Wave engineer.

查看更多
登录 后发表回答