Inserting Page Load Times into HTML Source as a HTML Comment

Discussion in 'Javascript' started by ste-m, Nov 1, 2006.

  1. ste-m

    ste-m Guest

    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
     
    ste-m, Nov 1, 2006
    #1
    1. Advertising

  2. ste-m

    Fred Guest

    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
     
    Fred, Nov 1, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9obiBQYXVsLiBBIChNQ1AgSUQjIDMwMTUxNzYp

    Comment : ASP.NET Performs 10 Times Faster than J2EE

    =?Utf-8?B?Sm9obiBQYXVsLiBBIChNQ1AgSUQjIDMwMTUxNzYp, Jul 1, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    703
    Kevin Spencer
    Jul 7, 2004
  2. Kylin
    Replies:
    1
    Views:
    389
  3. Alec S.
    Replies:
    10
    Views:
    10,169
    Alec S.
    Apr 16, 2005
  4. Richard S Beckett

    Inserting the same thing multi times into array.

    Richard S Beckett, Nov 19, 2003, in forum: Perl Misc
    Replies:
    8
    Views:
    121
    Richard S Beckett
    Nov 20, 2003
  5. Duke
    Replies:
    1
    Views:
    167
    Tom de Neef
    Apr 18, 2008
Loading...

Share This Page