...

View Full Version : XMLHttp request takes long time on first load



multiplex77
12-13-2007, 06:23 AM
Hi all,

I am using XMLHttp Request to call a web service and retrieve data from another website. My code looks like this:

// create an XmlHttp instance
objHttp = new ActiveXObject("Microsoft.XMLHTTP");

// Set up the post
if(async == true) //async is false by default
{
objHttp.onreadystatechange = function () { funcPtr(cntrlArray, codeArray, XPathStr) };
}

// send the POST to the Web service
objHttp.open("POST", szUrl, async);
objHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
objHttp.send(strEnvelope);

The last line (send method) always causes a 50 sec delay on initial page load. On subsequent page loads, the delay is less than 3 sec.

Is there anything I can to do to speed up the first execution of the Ďsendí method? Iíve tried setting async to true or false, but there isnít any difference in performance.

Thanks for the help.

rnd me
12-13-2007, 10:14 AM
since you are using post, it is not a caching problem.

perhaps the dns lookup is taking a long time?
subsequent lookups would be cached and therefore quick...

theres nothing about your code that is suspicious.

multiplex77
12-13-2007, 10:27 AM
Thanks for the advice. Appreciate it!

A1ien51
12-14-2007, 05:30 AM
Is this the first request after you run a new build or deploy the project. Certain serverside languages need to compile the page the first time it is hit and you might be seeing that.

Say you hit the page first time and you get the 50 seconds. If you kill that brower session. Start it up and go back is it still taking the 50 seconds?

If it does not than that means the only person that will take the hit is the first person to view it. Easy solution is when you deploy the application, make sure to hit the page.

Eric

multiplex77
12-14-2007, 05:36 AM
Hi Eric,

Yes, the page itself (ASP.NET) takes about 2 min to load the first time, but they Javascript (which includes the XMLHttp request) takes an additional 50 sec to execute the first time. Subsequently the page loads are pretty fast (about 3 sec) and the XMLHttp request is also 3-6 secs.

I'm just trying to see if there's any way the 50 sec XMLHttp request can be reduced. But I take your point that an easy solution would be to make sure to hit a page after the IIS is reset.

Thanks for the help.

A1ien51
12-14-2007, 02:02 PM
There is nothing you can do if it is the very first the the page is hit after an IIS restart. The first person that hits a page is going to pay a big penalty. All of the others should not see that issue.

Eric

multiplex77
12-20-2007, 04:45 AM
Already then. Thanks Eric! Appreciate it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum