Skip to content

Instantly share code, notes, and snippets.

@semlinker
Created July 25, 2022 10:34
Show Gist options
  • Save semlinker/78651a0ab46424b2ca370a4de87c6684 to your computer and use it in GitHub Desktop.
Save semlinker/78651a0ab46424b2ca370a4de87c6684 to your computer and use it in GitHub Desktop.
Get content length
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