Basically, I want to figure out whether I should download a file using AJAX, depending on how large the filesize is.
I guess this question could also be rephrased as
Sometimes HEAD can act differently than GET so I suggest something like this that aborts the request after getting Content-Length header:
new Promise(resolve => {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/a.bin', true);
xhr.onreadystatechange = () => {
resolve(+xhr.getResponseHeader("Content-Length"));
xhr.abort();
};
xhr.send();
}).then(console.log);