Connecting Tech Pros Worldwide Forums | Help | Site Map

Inserting Page Load Times into HTML Source as a HTML Comment

ste-m
Guest
 
Posts: n/a
#1: Nov 1 '06
Hi there,

I was wanting to calculate how long my web pages take to load, and to insert
this time into my HTML source code (not visible from the browser, but only
in source view) as a HTML comment.

I've found a JavaScript that does this here:
http://www.twohootssoftware.co.uk/code/loadtimejs.html

<script language="javascript" type="text/javascript">
var now = new Date();
var startTime = now.getTime()
</script>
<!-- <html>
...... put your code here.....
</html>
//-->
<script language="javascript" type="text/javascript">
now = new Date();
var endTime = now.getTime();
alert("Time taken to load page : " + ((endTime - startTime)/1000)+"
seconds");
</script>

Except that it puts the time in a popup window. I tried changing the code
to print the value as 'document.write' instead of 'alert' but I can't get
this code to stay hidden in the browser and only visible within the HTML
source code.

Can someone let me know how I can alter the above script to do this?

Thanks,

Ste



Fred
Guest
 
Posts: n/a
#2: Nov 1 '06

re: Inserting Page Load Times into HTML Source as a HTML Comment


ste-m wrote:
Quote:
Hi there,
>
I was wanting to calculate how long my web pages take to load, and to insert
this time into my HTML source code (not visible from the browser, but only
in source view) as a HTML comment.
>
I've found a JavaScript that does this here:
http://www.twohootssoftware.co.uk/code/loadtimejs.html
>
<script language="javascript" type="text/javascript">
Drop the language attribute, keep type.
Quote:
var now = new Date();
var startTime = now.getTime()
or:

var startTime = new Date().getTime();
Quote:
</script>
Script elements must be inside either a head or body element, they
can't be outside the HTML element. Error correction will (probably)
move them back inside.
Quote:
<!-- <html>
...... put your code here.....
</html>
//-->
<script language="javascript" type="text/javascript">
now = new Date();
var endTime = now.getTime();
alert("Time taken to load page : " + ((endTime - startTime)/1000)+"
seconds");
</script>
>
Except that it puts the time in a popup window. I tried changing the code
to print the value as 'document.write' instead of 'alert' but I can't get
this code to stay hidden in the browser and only visible within the HTML
source code.
The source code is the source code, not the generated code. You can
look at the innerHTML property, or use a DOM or generated code
inspector (there's one called "savegenpage" for Firefox) to see the
generated page.

Quote:
Can someone let me know how I can alter the above script to do this?
You can't.

--
Fred

ste-m
Guest
 
Posts: n/a
#3: Nov 1 '06

re: Inserting Page Load Times into HTML Source as a HTML Comment



"Fred" <ozfred@iinet.net.auwrote in message
news:1162351095.394437.93440@m73g2000cwd.googlegro ups.com...
Quote:
ste-m wrote:
>
Quote:
>Hi there,
>>
>I was wanting to calculate how long my web pages take to load, and to
>insert
>this time into my HTML source code (not visible from the browser, but
>only
>in source view) as a HTML comment.
>>
>I've found a JavaScript that does this here:
>http://www.twohootssoftware.co.uk/code/loadtimejs.html
>>
><script language="javascript" type="text/javascript">
>
Drop the language attribute, keep type.
>
Quote:
>var now = new Date();
>var startTime = now.getTime()
>
or:
>
var startTime = new Date().getTime();
>
Quote:
></script>
>
Script elements must be inside either a head or body element, they
can't be outside the HTML element. Error correction will (probably)
move them back inside.
>
Quote:
><!-- <html>
> ...... put your code here.....
></html>
>//-->
><script language="javascript" type="text/javascript">
>now = new Date();
>var endTime = now.getTime();
>alert("Time taken to load page : " + ((endTime - startTime)/1000)+"
>seconds");
></script>
>>
>Except that it puts the time in a popup window. I tried changing the
>code
>to print the value as 'document.write' instead of 'alert' but I can't get
>this code to stay hidden in the browser and only visible within the HTML
>source code.
>
The source code is the source code, not the generated code. You can
look at the innerHTML property, or use a DOM or generated code
inspector (there's one called "savegenpage" for Firefox) to see the
generated page.
>
>
Quote:
>Can someone let me know how I can alter the above script to do this?
>
You can't.
>
--
Fred

Hi Fred,

Thanks for your help with this, it's appreciated.

Ste


Closed Thread


Similar JavaScript / Ajax / DHTML bytes