简体   繁体   中英

jQuery server side push with ajax

I am in the middle of making a social network, and i want it to be as smooth as facebook.
Like if you look in a console and look at logging, it doesn't update all the time with ajax calls.

on my site i have to load: notifications(the number of new notifs and the notifs themselves), friend requests(same as notifications), online friends(if there are any online it will load the pictures of the online users.) thats 6 ajax calls that is loaded every 10 second. and this causes a huge bandwidth waste and server requests.

Therefore i thought, what if the SERVER told the CLIENT when there was a new update instead of the CLIENT asking the SERVER every 10 seconds.

i have googled this problem and read about ajax push, and a framework called comet. i just can't seem to find any info on how to implement this on jQuery.

I looked briefly into Comet. It appears to be ambitious, experimental and won't run on just any old server.

As I understand it, Comet doesn't really push as such but does something called "long polling", which I won't try to describe here. The web already has several good texts on the subject.

Personally, I would stick with the current plan (conventional AJAX) but make one general purpose call with all the necessary data bundled into an object and JSON encoded. This will reduce 6 requests down to one (every 10 seconds).

You can box-clever by returning nulls within the returned object for information that hasn't changed thereby minimising the length of each response.

As far as I know, you must make significant modifications on your webserver to get this thing to work. Also, server side php is not really a good option.

Somebody had already asked something similar here: Using comet with PHP?

You can try socket.io on node.js too. It works great for real time communication http://socket.io/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM