Good day. Tell me how to implement the most updated information on the client page, if there is a new information to display? As an example - chat. When user A sends a message, it is loaded by user B. Currently implemented with a simple setInterval, which every five seconds reloads records from the database, but I understand that this is very wrong.

  • Make sure that it does not load with the setinterval, but check if there are new entries (by quantity, by last entry, etc.). And if there are already new entries, then it has already loaded - Yuri
  • Well, for such cases is usually used some WebSocket. Well either with crutches setInterval'ами - SLy_huh

1 answer 1

You can send ajax requests to the server by timeout and send there, say, lastdate or something and receive only those that were lastdate later. lastdate will be stored on the client and updated accordingly, if the latest data came from the server / You can also use nodejs, socket. Ie to subscribe the client to the event