views:

298

answers:

2

Okay, so we all know that most modern browsers (without tweaking) are set to 4 parallel HTTP requests at a time to a single domain/subdomain, but how does long-polling AJAX affect this?

Say I have a long-poll on a 15 second interval. While the browser is waiting for a response during those 15 seconds, does that still eat up one of the 4 parallel lines effectively making any new tabs or page loads open to only 3 parallel HTTP requests?

+1  A: 
  1. It's not always 4, often it's 2.
  2. It is configurable to a higher number on the client side in many browsers.
  3. Yes it does eat up one of the parallel connections.
David M
There's really nothing that can be done about the lag/latency then? I was asking this because I was told to change my code to long-polling from regular polling AJAX since there was no way to do subdomain AJAX that pointed to the main domain (via a CNAME, with the purpose of breaking through the parallel connection limits).
krissauquillo
Why can't you use a subdomain or an alternative hostname within the main domain (e.g. ajax.domain.com rather than www.domain.com)? That would be the normal way around the restriction.
David M
I asked that over on ServerFault and they said the cross-domain security policy would just mess it up. I was hoping there was a way to do it also (get around the restriction), but I still haven't found anything.
krissauquillo
+1  A: 

You can have 2 concurrent requests via XHR..if you use more you might end up with unexpected results.

Use a Request Queue for more than 2 requests...each one being made after the previous one ends...

Some popular JS libraries implement a queue and can be used, or you could create one easily.

andreas