Discussions » Development

How to quickly get remote file size

§
Posted: 19-01-2020

How to quickly get remote file size

I'm needing to evaluate online file (image) real size, since HTMLImageElement doesn't contain any relevant property about it I'm forced to make another request by GM_xmlhttpRequest({responseType='blob', ....}) and query response.size to have it. It would be acceptable if it didn't cause performance issues (browser lags unresponsive for about 5-10s for images yet around 10MB, which is too high). I guess the long episode is evaluating response.size. Is there any other method quickly resolving to how many Bs were downloaded instead of counting the buffer elements?

woxxomMod
§
Posted: 19-01-2020
Edited: 20-01-2020

No need to fetch the actual contents in most cases. Simply make a method:'HEAD' request, which will only query the server, and extract Content-Length header from response.responseHeaders.

§
Posted: 27-01-2020

That's it, thanks

Post reply

Sign in to post a reply.