473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Inserting Page Load Times into HTML Source as a HTML Comment

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
Nov 1 '06 #1
2 4198
ste-m wrote:
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.

--
Fred

Nov 1 '06 #2

"Fred" <oz****@iinet.net.auwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
ste-m wrote:
>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.

--
Fred

Hi Fred,

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

Ste
Nov 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Paul Robinson | last post by:
I am developing a website in ASP that connects to a Sybase database. However, when I try to open a connection to the database the page will not load. The script does not timeout, nor the...
5
by: Pete Wason | last post by:
Hiall! I have a demo viewer page for javascript stuff that has three buttons "DEMO" "HTML" and "JSCR", and an IFRAME called 'viewer'. Initially, the IFRAME gets loaded with the actual demo...
3
by: Joachim Klassen | last post by:
Hi all, first apologies if this question looks the same as another one I recently posted - its a different thing but for the same szenario:-). We are having performance problems when...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
6
by: planetthoughtful | last post by:
Hi All, I have a C# ASP.NET page that submits back to itself to insert details from a form into a database table. When / if the user refreshes the page (and gets the standard warning that POST...
0
by: tom c | last post by:
I am going through "Walkthrough: Editing and Inserting Data in Web Pages with the DetailsView Web Server Control" found at http://msdn2.microsoft.com/en-us/library/sdba1d59.aspx I am using...
3
by: Nathan Sokalski | last post by:
I am recieving the following error on the second postback of a page I have written: The state information is invalid for this page and might be corrupted Stack Trace: ...
3
by: randy.buchholz | last post by:
I have been encountering strange behaviour on client machines where the pages truncate the display in the middle of the page. At some point the browser just goes white from one line to the bottom...
2
by: hakkatil | last post by:
Hi to all, I have a page that inserts excel sheet to access database. I am using asp. What I want to do is to check the inserting record if it is in the database. Basicly checking the dublicate...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.