Andy Smith
Andy Smith

Reputation: 3345

AJAX refreshing - only update when changed, is there a nice solution?

The more I work with AJAX the more I find myself faced with the same problem: I want data on the screen to be as up to date as possible but downloading the same data every second is over kill. The data may change only once every 30 minutes but when it does I would like this to be fed back to the user instantly.

Getting my server side scripts to return data describing the difference between the previous data can be a nice solution but is not always a possibility.

Is there a neat solution to this or is this just something I'm going to have to live with?

Upvotes: 0

Views: 191

Answers (3)

Ted
Ted

Reputation: 1690

You're looking for a comet or long-polling technique. Here is a general description with a nice explanation: http://www.ibm.com/developerworks/web/library/wa-reverseajax4/?ca=drs-
Also, the cometd website, which will work with jquery or dojo: http://cometd.org/ I

Another solution is Atmosphere: https://github.com/Atmosphere/atmosphere
Also here: http://jfarcand.wordpress.com/2010/06/15/using-atmospheres-jquery-plug-in-to-build-applicationsupporting-both-websocket-and-comet/

Upvotes: 0

devdRew
devdRew

Reputation: 4571

Nodejs and Socket.io. It works totally different. In your solution each opened window sends a request to the server, and as a result there is a very huge amount of useless request. Nodejs with Sokcet.io is a real PUSH engine. You can connect users by sockets, and push them notify, that the page should refresh, or updated data itself.

Nodejs and Socket.io links.

Upvotes: 1

you have to query the server every time, that's a given. what you can do is test, in the server, if there is any new data to update and, if not, just return something like 'false', so the callback doesn't do anything and less data is passed around each time.

Upvotes: 0

Related Questions