Discussions » Development

How to quickly get remote file size

§
Posted: 2020-01-19

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: 2020-01-19
Edited: 2020-01-20

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: 2020-01-27

That's it, thanks

Post reply

Sign in to post a reply.