Created
February 18, 2018 18:22
-
-
Save RinatValiullov/8b6782c1c36a9a5078ad48380249ade2 to your computer and use it in GitHub Desktop.
Navigation Timing API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Measuring the Critical Rendering Path</title> | |
<link rel="stylesheet" href="./style.css"> | |
<script src="./script.js" defer></script> | |
</head> | |
<script> | |
function measureCRP() { | |
let t = window.performance.timing, | |
interactive = t.domInteractive - t.domLoading, | |
dcl = t.domContentLoadedEventStart - t.domLoading, | |
complete = t.domComplete - t.domLoading, | |
js = t.domContentLoadedEventEnd - t.domContentLoadedEventStart; // Не работает(разобраться!) | |
let stats = document.createElement('p'); | |
stats.textContent = 'interactive: ' + interactive + 'ms, ' + 'dcl: ' + dcl + 'ms, complete: ' + complete + 'ms, ' + 'myjs: ' + js + 'ms'; | |
document.body.appendChild(stats); | |
} | |
</script> | |
<body onload="measureCRP()"> | |
<p>Hello <span>web performance</span> students!</p> | |
<div> | |
<img src="./preview.jpg" alt="image"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment