Suppose there's a file on the server: https://cdn.lr-in.com/LogRocket.min.js
How can I see the file size (preferably in KB) without downloading it?
Code snippet should be executable in chrome dev tools so no node.js code, please.
Unfortunately Is there a way to display the size of a file without downloading it? doesn't provide a reliable solution as there's no requirement that the Content-Length header is present in the headers of responses to HEAD requests.
From Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content (HEAD)
The server SHOULD send the same header fields in response to a HEAD request as it would have sent if the request had been a GET, except that the payload header fields (Section 3.3) MAY be omitted
The Content-Length header is one of these payload headers and there is no requirement to include it in HEAD responses (although, if it is included it must be correct.)
As you can see, the Content-Length header is not returned for this request!
fetch('https://cdn.lr-in.com/LogRocket.min.js', {method: 'HEAD'})
.then((result) => {
for (let key of result.headers.keys()){
console.log(`Header: ${key}`);
}
});