What format is the image converted when requested by the browser?

Asked

Viewed 412 times

3

This is more of a curiosity, I did a quick search and did not find something to explain how it works.

In practice when we develop, we have some methods to request an image from the server and display it on the browser screen in the client. One way depending on the case can be good to use, which is to leave the converted image in Base64, there are people who do not like it so, I believe that this way is good to use small images, decreasing the amount of files in the directories. Google images works that way, Whats emoticons app version web also works like this.

<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"></img>

The other, more traditional way is to fill the src with the path of the locality of the image. And then the curiosity arises, what method used by the server to convert the image to send it to the client (browser/browser)? example:

<img src="img/imagem.png"></img>

  • 3

    At first, there is no conversion at all - either the image exists on the server with the requested name, or it does not exist; and regardless of the name, the server can specify the format in the mime type and/or the browser can inspect the image to discover its contents (I don’t know exactly what happens when the mime type does not match the file format). By the way, Base64 increases data size by 33, not being a good option for large files, but as you actually pointed out to small files saves a round-trip to the server.

  • I think he wanted to use some other term instead of the word "convert".. that word changes the whole meaning of the question...

  • commenting a little more, part of the description of the question already answers the question itself.. rsrsr.. this scheme applying data:image is more for small images. Imagine 50 small images on a single page. That’s 50 requests to the server.. In a high traffic service, this becomes a significant cost $$.

  • Um yes, so each image has a new request to the server. My question is just how the server sends the image in the normal request as given in the example, is it in byte array? or some other type of data ? is more a curiosity.

1 answer

2


No conversion type occurs: the image is simply serialized into an array of bytes and this is sent in the body of the HTTP response.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.