2

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?

Robert Harvey
201k55 gold badges469 silver badges682 bronze badges
asked Jan 28, 2016 at 7:03
2
  • There is nothing radical about using Ajax for such an application. It's what people did before there was websockets. Commented Jan 28, 2016 at 9:04
  • Yes, I guess so, @Alternatex Commented Jan 28, 2016 at 20:56

1 Answer 1

0

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.

answered Jan 28, 2016 at 7:19
1
  • 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 :). Commented Jan 28, 2016 at 7:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.