Created
July 25, 2022 10:34
-
-
Save semlinker/78651a0ab46424b2ca370a4de87c6684 to your computer and use it in GitHub Desktop.
Get content length
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
function getContentLength(url) { | |
return new Promise((resolve, reject) => { | |
let xhr = new XMLHttpRequest(); | |
xhr.open("HEAD", url); | |
xhr.send(); | |
xhr.onload = function () { | |
resolve( | |
~~xhr.getResponseHeader("Content-Length") | |
); | |
}; | |
xhr.onerror = reject; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment