Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Long polling in iOS6 Mobile Safari

Mobile Safari on iOS 6 limits server connections to one per server, this appears to prevent long polling/comet in ajax web apps. Wondering whether it's recognised as changed behaviour from previous versions and is anyone aware of if it be fixed?

Mobile Safari - iOS 6-OTHER, iOS 6, Mobile Safari

Posted on Oct 24, 2012 4:37 PM

Reply
11 replies

Jan 7, 2013 8:13 AM in response to markdegroot

Ideally, you don't want to load images while the page is running if you can help it. It is better to preload them somewhere out of the way and just shift or fade them into place when you are ready.


However, if you did want to load data like this, it seems that all you really need to to is change your AJAX call to be synchronous instead. Then it seems to work. I don't have a real iOS6 device. I was able to reproduce and fix the problem in the simulator. Give it a try.

Jan 8, 2013 1:44 AM in response to etresoft

Long polling cannot be done synchronously because it would result in all webapp exectution waiting for the AJAX request to complete. The whole essence of long polling is that you do it asynchronously. For example: synchronously polling a service that takes 20 seconds to complete would result in the browser freezing for 20 seconds.


etresoft is right that preloading all images before the polling starts would ideally be the solution. Unfortunately, the result of the service we are polling will determine which images will be loaded. So this is not really an option for us.

Jan 8, 2013 9:12 AM in response to markdegroot

markdegroot wrote:


Long polling cannot be done synchronously because it would result in all webapp exectution waiting for the AJAX request to complete. The whole essence of long polling is that you do it asynchronously. For example: synchronously polling a service that takes 20 seconds to complete would result in the browser freezing for 20 seconds.

I will take that to mean that you haven't tried it yet. 🙂

Jan 9, 2013 8:00 AM in response to etresoft

etresoft wrote:


markdegroot wrote:


Long polling cannot be done synchronously because it would result in all webapp exectution waiting for the AJAX request to complete. The whole essence of long polling is that you do it asynchronously. For example: synchronously polling a service that takes 20 seconds to complete would result in the browser freezing for 20 seconds.

I will take that to mean that you haven't tried it yet. 🙂

I have now. And as I expected, synchronously polling causes the browser to hang. Also the XHR response never returns on the iPad but is cancelled after 10 seconds or so and then the second image is added. You can try it here: http://dev.negotica.net/iOSTest/index-sync.html .

Jan 9, 2013 9:55 AM in response to markdegroot

Ah. I see the problem. The image request interrupts the synchronous call.


I guess you will have to avoid assuming multiple connections are possible. The only reason I have ever used long polling is to get immediate updates. I make a request that will time out in 20 seconds or so but will return sooner if something notable happens. That notable event should be your queue that other resources need to be loaded. I typically return HTML to be inserted into the DOM and that will load any image resources it needs.

May 30, 2013 6:28 AM in response to fastundia

There's some uncertainty to this, but it seems that the "only one request" limitation only covers requests with HTTP keepalive - a new request to the same server will typically not be initiated if there's already another keepalive request going on. It also seems that this only affect some kind of requests - XHR requests or stylessheets seem to be OK whereas image requests seem to be blocked.


The workaround is however just to ensure that a "Connection: close" header is added for the long polling response (and that the headers are actually sent immediately instead of only the first time some actual data is returned over the long polling channel).

Long polling in iOS6 Mobile Safari

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.