Adsense
Popular Posts
- MySQL workbench -"Could not decrypt password cache"
- peer review (3)
- PHP, dump varailbes in a format way
- "Unusual traffic from your computer network" from blogger
- Install APXS in Redhat Linux
- JavaScript, remove trailing insignificant zeros after toFixed function
- Update member directory
- Set Windows path command line
- JavaScript: add days to current date
- DataTable table order by numeric, not by text
Monday, December 16, 2013
Measurement webpage performance
To measure webpage performance, we can use window.performance.timing object.
To calculate loading time, we can use loadEventEnd - navigationStart under use window.performance.timing.
Example code
<script type='text/javascript'>
function loadingtime() {
if (!!window.performance) {
// navigation time is loadEventEnd - navigationStart
var timingData = window.performance.timing;
document.querySelector("#loadtime").innerHTML = (timingData.loadEventEnd - timingData.navigationStart);
}
else {
document.querySelector("#message").innerHTML = "<p>This browser does not support the <code>performance</code> object</p>";
}
}
function init() {
setTimeout(loadingtime, 500);
}
window.onload = init;
</script>
<div id="message">
<p><span class="label">Load Time: </span><span id="loadtime"></span>ms</p>
</div>
Labels:
performance
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment