3

We would like to measure how much time it takes the browser the get a resource from the network. so for example if my page loads 10 images and 4 scripts I would like to know how much time it took the browser to load those resources from the network.

writing a browser plugin might work, but it's forces us to write different tool for each browser..what else can we do?

  • possible duplicate of [Javascript callback for knowing when an image is loaded](http://stackoverflow.com/questions/280049/javascript-callback-for-knowing-when-an-image-is-loaded) – jbabey Jul 17 '12 at 18:23
  • it's not a duplicate, the main challenge is to identify when the browser sends the request.(start time) – user1532644 Jul 17 '12 at 18:42
  • @jbabey This is not a duplicate since this question is about an even before the resource is requested instead of when it is finished loading. – DannyMeister Jul 17 '12 at 18:44
  • 1
    Unfortunately I do not believe that such a javascript/dom event exists. This is why most proposed solutions you are going to see will involve browser plugins which expose this, or external tools, like DynaTrace AJAX Edition. – DannyMeister Jul 17 '12 at 18:45

1 Answers1

0

Google Speedtracer should give you this information. I believe it shows the start of the request and the total elapsed time.

If you're concerned about browser specific quirks, you'd likely need to do some inline logging with JavaScript.


A pretty basic script such as:

<script type="text/javascript">
   var startTime = new Date().getTime();
</script>
<img src="yourimage.jpg" onload="console.log('new Date().getTime() - startTime')" />

ought to do the trick, but it's awfully invasive.

Evan Davis
  • 35,493
  • 6
  • 50
  • 57
  • looking for some javascript I can add to the page and not an external tool or a plug-in. – user1532644 Jul 17 '12 at 18:20
  • the script that you added is problematic, it starts counting when the browser loads that script, instead of when the browser actually sends the request – user1532644 Jul 17 '12 at 18:41
  • Ah, I see what you're driving at. No, I don't believe the browser exposes an `onBeforeLoad` event to JavaScript. – Evan Davis Jul 17 '12 at 18:52