Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Why JQuery AJAX request is slow

Hi I am creating a chat app in jquery and I have a problem init when I write a message to my friend it will take time then it will get sent but when I see in Facebook the message will get sent in a second. Why it will take like 4 to 5 seconds while it will get sent.

1 Answer

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

Hi Dustin Scott

AJAX isn't the best choice for real-time communication like in a messaging app. Each time you make an AJAX request you have to establish a connection with the server -- this takes time. A better real-time solution is using web sockets -- they let you open a connection to a server and keep it open -- the server can push data down to the browser without a specific request.

There are many tutorials on using websockets to create a chat app. Here's one that uses Node.js http://code.tutsplus.com/tutorials/using-nodejs-and-websockets-to-build-a-chat-service--net-34482

Thanks Dave.