Mobile app version of vmapp.org
Login or Join
Bryan171

: Best approach to creating self-updating content - i.e. chat rooms, shoutboxes and so on The only way I can think of to have a shoutbox or similar element update itself when somebody posts a

@Bryan171

Posted in: #Ajax

The only way I can think of to have a shoutbox or similar element update itself when somebody posts a new 'shout' and it needs to be loaded in everyone else's browsers is to have Javascript check every x seconds for any updates... This could get a bit resource intensive though I expect if many people were to leave their browsers open on the page, idling.

Is this the only way or am I missing something?

I've prefer to stick to only html, css, javascript (AJAX) and php.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Bryan171

2 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

As joshuahedlund's link notes, the traditional way of doing this is through a collection of techniques known as Comet, the most popular of which is long polling, as it's universally supported by browsers. With long polling, you simply make an XHR or JSONP request to the server, which the server does not respond to until it has a new event to report. When the connection times out, the browser automatically makes a new request, and the process is repeated.

However, HTML5 has introduced a new technology called WebSockets, which creates a true persistent connection between browser and server to allow for true server-push messaging. Even though browser support is limited still, you can already use this technology in production through libraries like socket.io, which has cross-browser fallbacks.

10% popularity Vote Up Vote Down


 

@Shakeerah822

For any application where you want instant updates as they're being made, it will be resource intensive. If you went the PHP way, you could make it that updates only showed after a page refresh, but that would frustrate users.

Another better way of doing it is to use the twitter method, where a JS popup shows saying "2 new posts have been made, click to read", this will lessen the consumption of resources because the actual data won't be pulled all the time and will only be pulled upon request by the user.

Of course this won't work for a chat app, which will require continuous rendering and I suggest you look at something like Node.js for programming something like this (there's probably code out there already for a chat app, you just have to implement it).

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme