I'd like to measure the loading time of a page using JavaScript. What do you mean?
- When someone accesses my page I want to start measuring the loading time.
- If this load time exceeds, for example, 500 ms, I want to display a link suggesting a simpler version of the page, as it is clear to me that this user's connection is slow.
Is there a script that does this?
EDIT
I had good answers, but I did not have 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 reach a standard of excellence in speed.
I found the approach interesting using window.performance.timing .
This example in the SOen apparently comes close to what I'm looking for. Has anyone used this approach?
EDIT 2
So I do not look annoying in the comments, I'd like to give you some more information:
The Date object of JavaScript solves part of my problem, but not with the level of excellence I expect.
- First because it is not necessary;
- Second that I can not measure network latency.
Latency is very important because I'm making a decision between a cloud service ( www.parse.com ) and an application server (< in> Java + Wildfly ) also in the cloud.
Parse offers me a fantastic development speed, but is the response time satisfactory? Will Wildfly , even though it also be in the cloud, will respond to me at a faster rate? I need metrics for this, and Date will not give me all the metrics I want.