Email conversation
From | Andrew Wiley |
To | Me |
Subject | Script to Time Page Load? How Did You Do It? |
Date | 28 August 2005 23:45 |
Hi, My name is Andrew Wiley, and I am an 8th grade computer geek (I run a
website and recieve tech support calls from my aunts). I was searching for
info on doing a science fair project on Windows browser speeds, and I
stumbled across your site. I was wondering, how did you time how long the
scripts took to load? I can see no real way to do it besides a stopwatch.
Thanks for your time,
Andrew Wiley
From | Me |
To | Andrew Wiley |
Subject | Re: Script to Time Page Load? How Did You Do It? |
Date | 29 August 2005 00:04 |
Andrew,
Second person to ask - you don't know someone called John Chan by any chance
do you?
> I was wondering, how did you
> time how long the scripts took to load?
> I can see no real way to do
> it besides a stopwatch.
Well, some teachers like stopwatches ;) but wherever possible, I use a timer
written in JavaScript:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Testcase</title>
</head>
<body>
<p><a href="testEnd.html" onclick="window.startedAt = new Date();"
target="theframe">test</a></p>
<p><iframe src="teststart.html" name="theframe" width="100%"
onload="alert( (new Date()).getTime() - startedAt.getTime() );">
</iframe></p>
</body>
</html>
It is not always possible to use onload on the iframe (and some browsers
like Netscape 4 need you to use normal frames). It is also possible to use
an onload handler on the new page itself:
alert( (new Date()).getTime() - parent.startedAt.getTime() );
Note that in sombe browsers, onload fires _before_ images have loaded, so
for the best accuracy, each image needs an onload event handler as well, and
you can count how many have loaded, and end the timer when the count reaches
the required number (plus one for the page itself). Failure to do this can
result in completely incorrect results. This technique is only possible when
you have a local server available that serves the pages for you, so you can
modify them (which I do), or if you use a proxy server to rewrite parts of
the page on-the-fly - on Windows, you can use proxomitron to insert scripts
at the start and end of every page.
None of these techniques take into account how long it takes to load CSS
files.
In the worst cases, you have to use a stopwatch.
Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/