Created
March 6, 2024 05:06
-
-
Save planetrenox/1bb0dfb1f34d67a7876febf37ede3dc4 to your computer and use it in GitHub Desktop.
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
function measureLoadTime(url) { | |
return new Promise((resolve, reject) => { | |
const startTime = performance.now(); | |
const script = document.createElement('script'); | |
script.src = url; | |
script.type = 'module'; | |
script.onload = () => { | |
const endTime = performance.now(); | |
const loadTime = endTime - startTime; | |
resolve(loadTime); | |
}; | |
script.onerror = reject; | |
document.head.appendChild(script); | |
}); | |
} | |
async function compareLoadTimes() { | |
const jsDelivrUrl = 'https://cdn.jsdelivr.net/npm/cute-html/+esm'; | |
const skypackUrl = 'https://cdn.skypack.dev/cute-html'; | |
try { | |
const jsDelivrLoadTime = await measureLoadTime(jsDelivrUrl); | |
console.log(`jsDelivr load time: ${jsDelivrLoadTime} ms`); | |
const skypackLoadTime = await measureLoadTime(skypackUrl); | |
console.log(`Skypack load time: ${skypackLoadTime} ms`); | |
} catch (error) { | |
console.error('Error loading the package:', error); | |
} | |
} | |
compareLoadTimes(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment