KoffeeKoder


  • While playing with the profiling feature of FireBug I found an interesting thing! When using MS Ajax to perform Ajax it takes approx 500+ calls to a simple server side method. The calls go deep into the MS Ajax framework and invoke different methods. However, if we use JQuery to make the same call it will only take <20 calls.

    Here is the code for the MS AJAX:


     <asp:ScriptManager ID="sm1" runat="server">
        <Services>
        <asp:ServiceReference InlineScript="false" Path="~/AjaxService.asmx" />
        </Services>
        </asp:ScriptManager>


    And here it the getCustomer method:


    function getCustomer()
    {
        console.profile("start");

        DemoScreenScrape.AjaxService.GetCustomer(function(response)
        {
            var customer = response;         
            alert(customer);                
        });
        
        console.profileEnd();
    }


    And here is the JQuery API Ajax call:


    function getCustomer()
      {
        console.profile("start");
       
           $.ajax({
       type: "POST",
       contentType:"application/json",
       url: "AjaxService.asmx/GetCustomer",
       data: "{}",
       dataType:"json",
       success: function(response)
       {     
         var customer = eval('(' + response.d + ')');
         alert(customer.FirstName);
         alert(customer.LastName);    
         
       }
     });

        console.profileEnd();
        
     }



    The console.profile("start") marks the starting point of the profiling and console.profileEnd() marks the end point of the profiling. This means that all the calls between the console.Profile("start") and console.profileEnd() will be captured in the FireBug profiler.

    Here is the reading from the FireBug profiler when MS AJAX was used to call the server side method.



    And here is the call to the same server side method using JQuery API:



    So, which Ajax framework would you use in your next application?



  • by krunal on 8/18/2008 11:26:57 PM
  • indeed jQuery is faster than ms ajax.

    but ms ajax also provides gr8 controls with drag and drop fun.

    so it's depends on the situation where you can use the appropriate ajax framework.

    Krunal
  • by Fahad on 8/19/2008 1:13:34 PM
  • I am just curious, have you tried running the JQuery test first and then ASP.net AJAX. Because the first time web service loads and the subsequent queries are faster. I have seen this behavior in my application using ASP.net AJAX. First hit is about 257 ms and rest are like 110 ms.

    - Fahad
  • by Mohammad Azam on 8/20/2008 6:59:55 PM
  • Hi Fahad,

    It does not matter which test I tried first the result is the same. MS AJAX is waaay slower then JQuery and many other frameworks. Primarily, because it makes many calls to many different functions before making the actual Ajax call.