Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPad ajax problems

Long story short: I had to create a chat functionality which seems to work on all devices except the iPad (and possibly the iPhone). Our customer uses their iPads to chat and so I have tried to solve the problems for past 7-ish months.

That's how long it took for me to somewhat pinpoint the problem.

The problem is clearly in the iPad's browser. I run JSON Ajax requests using the library jQuery. The requests are fine, they do not contain errors. At some point, the iPad just doesn't run Ajax requests at all. I dont know why, I cant find why. Every Ajax request is logged, but at some point the server doesn't get any requests. I have asked a zillion times and the customer is positive they are only touching the ipad to prevent it from being locked.

I have reduced the rate of requests to approximately 15 requests per minute, but that didn't work.

So, my question is: Is there any information known to man why the ipad abruptly stops sending Ajax requests after 10-15 minutes?

like image 559
Tim S. Avatar asked May 29 '12 15:05

Tim S.


1 Answers

Putting this here, as in comment there isn't any syntax highlighting.

I've made a super minimal test page here: http://www.focalstrategy.com/tests/ajax.php

The code is:

<?

if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {

echo date("F j, Y, G:i:s a");
exit();

}

?>
<!doctype html>
<html>
<head>
    <title>AJAX test</title>
</head>
<body>
    <h1>Ajax Test</h1>
    <p>This page makes an AJAX request every 5 seconds and replaces the div below with the returned date.</p>

    <div><p id="date"><?= date("F j, Y, G:i:s a") ?></p></div>
    <div><p><span id="count">0</span> updates made.</p></div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script>
    var count = 0;

    var getDate = function() {
        $.get('/tests/ajax.php', function(data) {
            $('#date').html(data);
            count = count + 1;
            $('#count').html(count);
        });
    }
    setInterval(getDate, 5000);
    </script>

</body>
</html>

So, I ran this for an hour, and didn't have any issues, the iPad (fully updated) ran fine throughout, without missing any.

I also ran this on Chrome and recorded it's behaviour. This looks like this:

Chrome Profiler view, showing graphs for DOM Node, Event Listeners and memory usage.

(Full size)

There's some weirdness here, in that at first the number of event listeners stays constant, then after a while goes mad,, increasing up to 56 listeners before dropping to 1 again. The DOM Node Count also repeatedly spikes, as high as 424. Both have fairly odd behaviour bearing in mind the simplicity of this code.

Perhaps on your app the number of Dom Nodes being tracked, or the number of event listeners is reaching some value causing the iPad to lose track of what's happening, or something similar.

It's also worth noticing that the memory usage ramps up until garbage collection happens. That's what is meant to happen, though perhaps it's less efficient on the iPad.

Edit: I've tested it again on a clean profile, many of the Event listeners are due to extensions – the same behaviour happens, but not to same degree, also background values are 0-1 rather than 15-20

like image 197
Rich Bradshaw Avatar answered Oct 16 '22 21:10

Rich Bradshaw