I have a chat on my web site and it needs to send many AJAX requests to my server (at least 2 times per second) in order to check if there are new messages.
Is there a way to reduce the number of requests and reload messages only after they have been posted?
I know that there are no possibility to use sockets (because I can't use flash, java or features of HTML5), but maybe there is some trick dealing with keep alive option of HTTP 1.1?
Yes, there is an easy way to do this. Effectively, what you do is you increase the timeout for your ajax call to a long timeout (say, 5 minutes). Your server receives the request and then holds it, occasionally checking for new responses. Then, when a new response is warranted, it simply responds to the request, and your client receives the update.
If no response is had within 5 minutes, your client simply timeouts and starts a new ajax request. Your server, if it hasn't responded within 5 minutes, usually then just terminates the held request to get it out of the queue.
Effectively 'server-side' pushing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With