views:

50

answers:

3

Hi
I noticed that jquery ajax request sometimes take about 1-2 seconds before the responce comes is this normal and is there any way to short that time to minimal?
The responce type is json and it's small html code.
Thanks!

A: 

Depending on how you coded your solution, the speed largely depends on internet connection from you to server. You can try launch it on localhost to see if it takes that long, if it does, then something is wrong with your code. If you could post a simplified code illustrating the problem we can try to figure it out :D

FurtiveFelon
Actually the responce contains small html code.
Mick
+2  A: 

Here are the places the slowness could be:

  1. Database <--> Web server latency
  2. Database Query
  3. Database <--> Web server bandwidth
  4. Server side script code
  5. Web server <--> client latency
  6. Web server <--> client bandwidth
tster
+1  A: 

In short, yes, a delay is normal after the request is sent and before the response comes. However, you didn't specify exactly what is happening with the request.

Is it just the request that is taking up to much time? Is the delay before it sends the request? I work with jQuery's ajax engine all the time in our app. I haven't really ever seen latency before the request is sent. What do you use to monitor the ajax request? You can check this using firebug. Enable the net panel and watch the timing.

If the only delay is after the response comes then it may be the HTML that is returned. Is there a lot of HTML that is returned? Is there javascript in the HTML? Are you injecting the HTML in the page and the delay is after that?

Dale