Created
September 4, 2019 10:32
-
-
Save willmendesneto/ed6be58debc611fcd1c0f3289d3a744f to your computer and use it in GitHub Desktop.
Example of User Timing API usage
This file contains hidden or 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
const fetchSomeData = async () => { | |
const measureName = 'fetchSomeData'; | |
const startMark = `[START]: ${measureName}`; | |
const endMark = `[END]: ${measureName}`; | |
try { | |
const url = 'your-url'; | |
// starting the User Timing API marker for this request | |
performance.mark(startMark); | |
const data = await fetch(url); | |
return data; | |
} catch (error) { | |
console.error('Oops!', error); | |
} finally { | |
// Finishing the markers and sending the results | |
performance.mark(endMark); | |
performance.measure(measureName, startMark, endMark); | |
performance.clearMeasures(measureName); | |
performance.clearMarks(startMark); | |
performance.clearMarks(endMark); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment