tags:

views:

1070

answers:

7

Hi,

I am using $.ajax to update some values in the database. when the page makes the ajax call for the first time, it is slow. it is taking like 5 or 6 seconds to return the result. after the first request, it is fast. I am not sure if there is a way to make the first call also fast. if you have any ideas, please let me know.

Thanks, sridhar

+1  A: 

What type of service is the method calling? It's probably the service it is calling that is slow, not jQuery.

John Sheehan
I think that John is probably right, but I would add that if you are running your server under the debugger, it may well be the overhead of the debugger loading debug information for referenced assemblies, rather than the method itself.
Craig Stuntz
A: 

Is your ajax call against an ASP.NET handler? If so, then it's probably from ASP.NET loading the app domain.

barneytron
A: 

You should log the server-side script execution time. I agree with John, and suggest you focus on the server rather than jQuery at this moment.

Jonathan Sampson
+1  A: 

My suspicion would be that the database is doing some caching and subsequent requests are filled from the cache. If this were only happening on the first request of the data, regardless of the data involved, then I would suspect that the web service that you're connecting to needs to be loaded into memory on the first operation.

tvanfosson
A: 

Install Fiddler for IE, or run the Firebug console in firefox and take a look at the request / response headers. You'll see where the delay happens.

Mike Robinson
A: 

Hi all,

Thanks for the response. It is not the server side code that is slow. If it is, then it would be slow every time. This is what we did to make it work faster. When the page loads, in the document.ready function we are making a fake webservice call to eliminate the initial delay. Now it is working fine. The server side code is not actually a web service but a page method in asp.net. Page methods can be used as webservices in asp.net. I will run the firefox and see what happens.

Thanks, sridhar.

Sridhar
A: 

If it only happens in IE7, this is because of IE7 rendering slowly. It might only happen the first time since jquery get/ajax will use the request in a way that can be cached by the browser.

Basically, it isn't clear if it's the rendering or the server.

It still could be the server though - query caching (or other kinds of caching) means the query can be slow first time only, then fast.

Jonathan Hendler