Inserting Page Load Times into HTML Source as a HTML Comment

S

ste-m

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
 
F

Fred

ste-m said:
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.
var now = new Date();
var startTime = now.getTime()

or:

var startTime = new Date().getTime();
</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.
<!-- <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.

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

You can't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top