0

I am curious How to dynamically update field without refresh and without killing the server with queries? Stackoverflow has this functionality when someone answer our question it indicates on the top of the page but my question is : Is this based on ajax and Jquery

setInterval();

function or there is another way? I can imagine how many visits has this website per day and if setInterval() is made to send ajax request to the server each 10sec for example I think this will kill the server.. Am I wrong, is there another smart way that saves server performance or even here is uset setInterval(); to alert users? In the console I don't see any ajax request running.. What I am missing? Thank you in advance for any suggestions or samples !

thecore7
  • 484
  • 2
  • 8
  • 29

1 Answers1

1

What you are looking for is a "push"-like technology. There are several ways to do it, Ajax being the most basic and the least preferred due to reasons you already mentioned. Long-polling, server sent events and web sockets are the other methods.

Popular libraries like Socket.io make it simple enough to get started, taking care of browser dependencies by choosing the right technology compatible with the browser.

This SO answer summarizes these technologies for you to get started. Or this article, and there are more if you search by these terms: long-polling, sse, websockets.

Community
  • 1
  • 1
show-me-the-code
  • 1,553
  • 1
  • 12
  • 14