I've written a chat using ajax. In a nutshell, every few seconds, an ajax call is fired and data is getting updated. The ajax function is a setTimeout in itself, so the loop goes on.
What's bothering me is that, when a page is open on my computer, it will send requests forever. So if I reduce setTimeout time to have more live/instant experience, I'd be firing a lot of redundant requests because most of them aren't necessary. I'd like to know if there's a way to only send the request if there's an update on the server. So instead of sending ajax and wait for response, just "listen" for a response?
Maybe I'm trying to ask if there's a way to have a response on a page without "requesting by ajax"?
All alternative ways are welcome.
Thanks for your time.