6
I would like to measure the load time of a page using Javascript. How so?
- When someone accesses my page I want to start measuring load time.
- In case this load time exceeds, for example, 500 ms I want to display a link suggesting the use of a simpler version of the page, because it is clear to me that the connection of this user is slow.
Is there any script do that?
EDIT
I got a good answer, but I didn’t get an answer exactly as I expected. I’m sure there are more elegant approaches than putting a timer on the page. I want to identify bottlenecks to arrive at a standard of excellence in the speed category.
I found the approach interesting using the window.performance.timing.
This example in Soen apparently comes close to what I’m looking for. Someone has already used this approach?
EDIT 2
So that I do not seem boring in the comments, I would like to provide some more information:
The object Date of Javascript solves part of my problem, but not with the level of excellence I hope.
- First because he doesn’t have to;
- Second with it I can’t measure network latency.
Latency is very important because I’m making a decision between a cloud service (www.parse.com) and an application server (Java + Wildfly) also in the cloud.
The parse offers me a fantastic development speed, but is the response time satisfactory? Will the Wildfly, even though I’m in the cloud, will you answer me with more speed? I need metrics for that, and Date won’t give me all the metrics I want.
window.performance.timing
maybe it’s a good way...– Sergio
@Guill, I don’t think it lacks the question, the content has an explicit question. . . . Edgar, cool this info that Sergio passed; would suggest perhaps vc store a dozen values of timing in a local object Torage and be able to average.
– brasofilo
@brasofilo found it interesting, I will test the methods passed so far.
– Edgar Muniz Berlinck
So enriching what @Sergio said, I found interesting, and has a good explanation right here in the OS: http://stackoverflow.com/questions/16808486/explanation-of-window-performance-javascript
– MarceloBoni
Sleek approach?
– Guill
@Guill put it. I liked your answer, it works, but I’ll wait for more approaches. I wonder if anyone has used an approach with the windows performance.. I intend to study it myself, but while I don’t have time I’ll wait for more answers. Just don’t think I didn’t like your answer :), she is good and I want to know if a better one can come up even better.
– Edgar Muniz Berlinck