For newer browsers, you can use web sockets to open a continuous connection to the server, and then the client / server can send messages to each other whenever they want.
For older browsers, as is usually done, the client must “poll” the server to ask the server for some regular schedule if the server has new messages. Typically, the server cannot connect directly to the client due to firewalls, local security settings, an unknown location, etc. Therefore, the client must connect to the server. The survey can be either regular or a survey every 60 seconds with an ajax call to ask if there is something new or there may be a longer poll when the client asks if there is something new and if there is something new, the server returns data immediately. But there is nothing new, the server freezes at the polling request for some period of time, expecting to see if there is something new. In the end, the server will either return that it has nothing, or will return with a new message, if any. When the client receives a response, it starts the sequence of "long polls" again. Comet is an example of a "long survey" in library form, which simplifies its implementation.
source share