0

I found that the ajax response times were very different using different browsers. The server (mongoose) was running locally so network issues are excluded.

These are my findings:

  • Firefox 11-23ms
  • Chrome 6-130ms
  • Safari (webkit) 1004-1020ms
  • Maxthom (webkit) alternates between 30 and 1030ms
  • Arora (qt/webkit) 1017-1025ms
  • embeddedchromium alternates between 15 and 315ms

And here is the code for everyone to check:

<html>
    <head>
        <title>Embedded Response Slow demo</title>
    </head>
    <body>
        <script>
            var time = 0;

            function mouseClicked()
            {
                time = new Date().getTime();

                var xmlhttp = new XMLHttpRequest();

                xmlhttp.onreadystatechange = function()
                {
                    if (xmlhttp.readyState==4 && xmlhttp.status==200)
                    {
                        time =  new Date().getTime() - time;
                        document.getElementById('link').innerHTML 
                             = "Response took "+time+"ms.";
                    }
                }
                xmlhttp.open("GET","responsetest.html?q="+time,true);
                xmlhttp.send();
            }
        </script>
        <div><a onclick="mouseClicked()" id="link" href="#" >click me</a></div>
    </body>
</html>

For a responsive GUI, I really need to work this out. Does anybody have an Idea how I can get short response times consistently?

(I reworked the whole question to be simpler and contain code. Now I removed jQuery completely from the equation and added Safari results.)

clemens
  • 422
  • 2
  • 12
  • I assume you are aware that jQuery will also cache ajax requests at the client side? This may cause inconsistant timings for you? – Pushkar Sep 21 '12 at 07:44
  • You are loading jquery library from a remote server, it's not on your server local, so network access to the library can have a hit on the execution. Try downloading the file to your server, loading it from within your project and taking metrics again. – Bardo Sep 21 '12 at 08:07
  • @Apache Fan: As it was a post request nothing got cached. I did switch it to get with "cache: false" now, which didn't change anything substantial (same relation, just 5-7 ms better) – clemens Sep 21 '12 at 08:15
  • @Bardo: I changed that too and updated the source code above. Nothing changed, unfortunately! – clemens Sep 21 '12 at 08:16
  • Maybe there is some differences on Date class operations between the javascript engines of each browser? Try just to post the return time instead of substracting it from a 0 moment. – Bardo Sep 21 '12 at 08:24
  • Well, the thing is that I see the output of my browser and my server. The latter logs all requests to the console and I see that these measurements are somewhat correct... At least those over 200ms. – clemens Sep 21 '12 at 09:31
  • Hmm, I'll try to use WebSockets for this purpose and will report back results. Unfortunately, most browsers support different versions of it. – clemens Sep 24 '12 at 02:40
  • possible duplicate of [Loading animation doesn't show up until after ajax call completes in Safari/Chrome](http://stackoverflow.com/questions/3535373/loading-animation-doesnt-show-up-until-after-ajax-call-completes-in-safari-chro) – Paul Sweatte Apr 25 '14 at 20:29

0 Answers0