0

I have an image element:

<img id="my_image" src="https://crossorigin.url/photo.jpg" onLoad=whatToPutHere() />

and after I load it from an external source (there is no CORS policy issue) I want to know the size of the image that will be the same same size in disk if I right click on the image and save it on my computer.

Can I avoid making a HEAD request to get the Content-Length at "https://crossorigin.url/photo.jpg" ?
Is there any other way to do it with pure javascript ?

but-why
  • 533
  • 3
  • 10
  • The size on the disk is not necessarily the same as in `Content-Length` – Andreas Dec 10 '20 at 11:39
  • @Andreas Both is fine, either content-length or size in disk, but not have to make another request. – but-why Dec 10 '20 at 11:41
  • You can avoid another request by not including the src in the HTML, and - if it's possible - loading the image to get its filesize then adding the src attribute to the img tag. If that still requests twice you may, instead, be able to convert the loaded image to data-src and dump that into the src attribute. – Popnoodles Dec 10 '20 at 11:47

0 Answers0