views:

1855

answers:

5

I'm using jQuery to post to an ASP .NET Web Service to implement a custom auto-complete function. The code works great, except it's slow in FireFox (can't get it to go faster than 1 second). IE is blazing fast - works great. I watch the post in Firefox using Firebug.

Here's the service code:

<ScriptService(), _
WebService(Namespace:="http://tempuri.org/"), _
WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1), _
ToolboxItem(False)> _
Public Class TestWebSvc
  Inherits System.Web.Services.WebService

  <WebMethod(), _
  ScriptMethod(ResponseFormat:=Script.Services.ResponseFormat.Json, UseHttpGet:=True)> _
  Public Function GetAccounts(ByVal q As String) As Object

    'Code taken out for simplicity

    Return result

  End Function

End Class

And the jQuery ajax call:

$.ajax({
    beforeSend: function (req) { req.setRequestHeader("Content-Type", "application/json"); },
    contentType: "application/json; charset=utf-8",
    type: "GET",
    url: "http://localhost/Suggest/TestWebSvc.asmx/GetAccounts",
    data: "q='" + element.val() + "'",
    dataType: "json",
    success: testWebSvcSuccess
  });

As you can see, I've tried to use the HTTP GET verb instead in hopes that that would make the call faster. As it does not, I'll probably switch it back to using POST if I can. Right now I'm just focused on why it's super fast in IE and super slow in Firefox.

Versions: jQuery 1.3.2; Firefox 3.0.11; IE 8.0.6001.18783 (64-bit)

Thank you for any insight you can provide.

+1  A: 

I'll bet IE is caching it. For some reason, IE is a little more aggressive (old post but I still see the issue) when it comes to caching, and this is probably no exception. Try and run a couple of sanity checks to see if its' really caching it.

altCognito
Yes, it's possible. caching is true by default for GET requests.
ScottE
When I used POST instead, IE was still fast, and Firefox was still slow.
Brandon Montgomery
I disabled caching and I get the same behavior.
Brandon Montgomery
A: 

Is there a reason why you are using beforeSend: ?

You can just set the content type as an option, like so:

contentType: "application/json; charset=utf-8"

Also, why not make the url to the web method relative or absolute? I doubt the full uri would make a difference, but you never know.

ScottE
+1  A: 

So instead of just hitting "Run" in Visual Studio, I created an application in IIS and accessed the page from there - now it works fast in both FireFox and IE. Strange... I'm still a little wary about this - I have a feeling this might come back to haunt me somewhere, but for now it looks like the problem is resolved.

Brandon Montgomery
Wow, interesting. I was having this exact same issue, but with a MVC + Ext JS app running in VS. FF (and also Chrome) would never return an Ajax post in less than 1 second while IE was instantaneous. I spent a couple of hours trying to figure this out until I found this thread. Installed into IIS, now it blazes in all browsers. I assume that MS has somehow optimized the VS + IE combination (shocking...). Thanks for this -- I was really freaking out that my app was going to be unusable.
bmoeskau
+1  A: 

I know I'm late to the party for this question, but I just had to deal with a similar situation. Turns out the 'problem' was using http://localhost instead of 127.0.0.1

IE performed fast using either URL. FF was fast with using an IP address, but added a 1 second delay with using localhost.

Pat
+1  A: 

Sorry I too am late to this question. Cassini (VS Web Server) + Firefox have known performance issues for any server request (not just ajax/webservice requests). The 127.0.0.1 solution is one fix - another is to change a setting in firefox:

http://blog.anofsinger.com/2007/08/firefox-slowness-with-cassini-vs-web.html

jskunkle