I can easely use javascript to auto refresh the page every 10 sec for example but, isnt this going to overload the page having to ask for any change every 10 secons? is there a more efitient way to do this. Some body told me once than there is a way having the client side waiting for a response from the server that only sends it when it really has some change, for example some budy wrote a text in the chat. Is this really factible to do? is there a better way?.
Why refresh a chat page? Why not just check the server to see if there are new posts/chats etc. If so, append those to your chat box.
Have your timer (setTimeOut) fire say ever 5 seconds:
Quick pseudo code:
function updateChat()
{
//Query a web service on the server for new text chat
//If successful append the chat to the chat area
//Call timeout again.
setTimeout(updateChat, 500);
}
Edit: Seeing you have .NET I will assume you're using ASP.NET. Here's a link to a demo chat program:
http://trappedinhoth.blogspot.com/2009/04/ajax-jquery-chat-demo.html
Update: Also another ASP.NET / JQuery chat prog that will soon be available on CodePlex.
You can apply outputcache on server side. IN this way server only need to generate 1 answer per each 10 seconds
You can try using the new WebSockets technology in JavaScript. It is not supported in many browsers (only Firefox 4, Chrome 4, and Safari 5 currently support it), but it allows the connection to the server to remain "open" and then the server can send a message to the client. More info: