Amar Banerjee
Amar Banerjee

Reputation: 5012

how to make a popup chat application without using ajax

I have made a dating website where I have use one to one chatting application like facebook. When one user send any message to another user it showing into their popup chat box, but I have done this using ajax. Which I have run in every interval using javascript setInterval function. But I think the process is not optimize one. I don't want to make unnecessary request to the server each time, rather it only trigger when there is some new message for that user. Is there any other way to do it or any other protocol which using by big site like facebook, gmail?

Upvotes: 3

Views: 2524

Answers (4)

Siot
Siot

Reputation: 95

Server-Sent Events seems to be another option.

A chat example: http://motyar.blogspot.com.es/2012/01/simple-chat-application-with-html5.html Documentation: https://developer.mozilla.org/en-US/docs/Server-sent_events

Upvotes: 0

centree
centree

Reputation: 2439

Read into Long Polling. It's what facebook uses. Basically your client makes one Ajax call and nothing gets returned until there is data to push to it. I'm pretty sure it requires some custom server configuration so if you're developing on shared hosting it isn't going to cut it. Long Polling would be the right, albeit, more complicated way of doing this if efficiency is what you want.

Upvotes: 0

Tom Studee
Tom Studee

Reputation: 10452

I agree with Josh that WebSockets would be worth looking into, however if you don't have access to the server you could use something like Firebase for the back end.

https://www.firebase.com/index.html

Upvotes: 0

Josh
Josh

Reputation: 44906

You could do this using WebSockets, but that requires both a server implementation and a web browser that supports it.

Another technique is to use Long Polling, but again, this requires work on both the client and the server. The advantage is that this is a cross browser compatible technique.

Upvotes: 5

Related Questions