Usually, real-time web-apps are built with websockets, right?

Well, let me be radical here - what if I used Ajax?

Okay, okay, I know it has its limitations. You can't build Agar.io, sending data packets up to fifty times a second, with latency in the milliseconds.

But what about an app that had real-time updates that were a bit less frequent. Maybe receiving notifications with in a few seconds, or a turn-based game?

Is it acceptable to use Ajax.post() every, say, few seconds to receive updates from a, say, PHP script, getting information from an SQL database? As opposed to either RTS games, or the Stackexchange model, where information is loaded when the page is loaded, instead of while the page is open.

So would there be any issues with using this model? Would it lag the client's computer or have some problem related?


1 Answer 1


In general, the overhead involved with AJAX requests is higher. If an Ajax request has, say, 1K of transport overhead, then sending 50 bytes over a single request means that your transfer of actual data is only about 5% efficient.

Ajax requests are typically made to RESTful resources. Socket communication is a persistent connection, and seems more suited for real-time, dashboard-style updates.

Stack Exchange uses a custom socket library to send updates to its pages in real-time, including edit notifications, comment additions and changes to voting tallys.

  • Oh okay, I see. I actually didn't notice that updates were in real-time. That was insightful advice, very clearly stated. I find the information available confusing - Stackexchange to the rescue again! ;) Thanks @robertharvey :).
    – Luke
    Jan 28, 2016 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.