Ajax Long Survey Performance Improvement

I am writing a webapp ( Firefox only ) that uses a lengthy survey (using jQuery ajax features) to send more or less constant updates from the server to the client. I am concerned about the consequences of leaving this regime for long periods of time, say, all day or night. The basic code skeleton is as follows:

function processResults(xml)
{
    // do stuff with the xml from the server
}

function fetch()
{
    setTimeout(function ()
    {
        $.ajax({
            type: 'GET',
            url: 'foo/bar/baz',
            dataType: 'xml',
            success: function (xml)
            {
                processResults(xml);
                fetch();
            },
            error: function (xhr, type, exception)
            {
                if (xhr.status === 0)
                {
                console.log('XMLHttpRequest cancelled');
                }
                else
                {
                    console.debug(xhr);
                    fetch();
                }
            }
        });
    }, 500);
}

(Half a second of "sleep" is that the client does not clog the server, if updates return to the client quickly - usually they.)

, Firefox. , , . , Firebug fetch, , . , Firebug, 4 5 , .

, , , , Ajax . JS 1.7 "yield" , , , , .

, , ? / , 8 12 ? " ", , ?

+5
4

, FireBug. - console.logging, , , , .., , .

, , .

+2

, processResults().

- , .

, fetch() . .

, Firefox Add Monitor, .

+2

4-5 . setTimeout $.ajax - , . . , . .

, , . $.ajax jQuery ( ), processResults.

+1

fetch() . , , - , . , , . 3-4 , , jQuery - "" , .

jquery . , , yhou , . $.ajax() , 500 .

function myLongPoll(){
    setTimeout(function(){
        $.ajax({
            type:'POST',
            dataType: 'JSON',
            url: 'http://my.domain.com/action',
            data: {},
            cache: false,
            success:function(data){

                //do something with the result

            },
            complete: myLongPoll, 
            async : false,
            timeout: 5000
        });
   //Doesn't matter how long it took the ajax call, 1 milisec or 
   //5 seconds (timeout), the next call will only happen after 2 seconds
   }, 2000);

, , $.ajax() . , console.log() $.ajax().

+1

All Articles