I want to write how long it takes to parse one of the pages for my website. I've got the setting up of the time variable at the top of my script then have a lot of stuff which is done in-between. I then display time elapsed at the bottom (after the whole page has loaded).

Is it possible to display the time on top of the page?

Recommended Answers

All 6 Replies

Member Avatar for P0lT10n

I think that you are not able...

Of course it's possible, but seems a bit time wastefull.

You have 2 (edit: 3) options that I can think of:

1. Use CSS; i.e. Put it in a div with an id of "elapsed" and then set in your style sheet that this div should fit somewhere nicely at the top of your page.

2. Use the output buffer; Put in a placeholder at the top of the page for the elapsed time then use a regular expression to replace it with the time (although the time elapsed will be (slightly) out of sync now since it will be complete before the page has been rendered)

3. JQuery. Once you have figured the elapsed time run a JQuery function to update the div at the top. I'd definitely recommend this option.

Hmm, my skill level at the moment isn't enough to deal with this I don't think. It's too much of a big deal having the results at the bottom of the page though so I guess I'll just stick with that!

Fair enough. I would seriously recommend learning the basics of JQuery though. It sounds (and looks scary) at first but it's a great resource and you'll be amazed at the amazing things it can do on ANY browser with very little hand written code. Showing, hiding and updating the text in <div>'s on the fly has been such a priceless thing for me over the past few years. It will really help push you in right direction making you an all round better developer even if you barely use it, but just knowing of its capabilities or perhaps learning another similar resource.

Why would you want to do that in first place.

I mean if your site performance is really good then you can but not if your site performace is average.

Also this can be easily done using jquery.

Let me know if you need any assistance.

Well, yes if it can be easily done then sure Vaibhav I'd love some assistance on making it happen!

And yeah (kevindougans) I'm definitely going to learn it sooner or later. It's just that this year I'm pretty much busy with learning other stuff so have to squeeze in some time to learn web development here and there. Thanks on the advice though!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.