Skip to content

Instantly share code, notes, and snippets.

@MichaelCurrin
Last active January 13, 2021 10:09
Show Gist options
  • Save MichaelCurrin/74f7147658da5f24fc6f6cc66c07009a to your computer and use it in GitHub Desktop.
Save MichaelCurrin/74f7147658da5f24fc6f6cc66c07009a to your computer and use it in GitHub Desktop.
Page performance metrics

Page performance metrics

Calculate load performance of a webpage, for any page you visit.

No libraries needed - this uses performance timings that are builtin to modern JS in the browser.

Based on Navigation Timing API doc.

Usage

  1. In your browser, open the Dev Tools or right-click and Inspect a page.
  2. Copy the JS below.
  3. Paste it into the JS console.

Your output will be something like:

{
  "pageLoadTime": 2.868,
  "connectTime": 0.634,
  "renderTime": 1.834
}
function logPerformance() {
const perfData = window.performance.timing;
const ms = 1000;
const pageLoadTime = (perfData.loadEventEnd - perfData.navigationStart) / ms;
const connectTime = (perfData.responseEnd - perfData.requestStart) / ms;
const renderTime = (perfData.domComplete - perfData.domLoading) / ms;
const results = {
pageLoadTime,
connectTime,
renderTime
};
console.log(JSON.stringify(results, null, 2))
}
logPerformance()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment