Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http request - IMG vs TEXT?

The timeline shown here (captured using IE’s F12 developer tools) illustrates how IE handles a page where an <img> tag is located after of a bunch of text :

enter image description here

The second row shows the retrieval of the image. Since the image is small, all of the image data is included with the HTTP response headers in the same packet.

However - The next timeline shows what happens when the <img> tag is located close to the beginning of the file so that it’s in the first packet of data received by IE:

However, the request for the image starts shortly after the first packet of HTML arrives.

As a result, it takes less total time to retrieve the page and the image

But (IMHO) it is better to put images (with defined dimensions) on the bottom of that page. ( so that the page will load faster)

However - by my example it shows that the page is loading faster when the img is on top.

What am I missing ?

P.S. my question is a briefly summarized text of this section

like image 623
Royi Namir Avatar asked Dec 19 '12 08:12

Royi Namir


People also ask

Is it better to use background image or IMG tag?

It is widely known that using the image tag is better SEO practice than using background images because of the screen reader implications.

Can an IMG element contain text?

No. There is no text inside the img. According to the specs, the img element is a void element, i.e. it doesn't have any content or an end tag.

What is the difference between IMG and picture tag?

The <img> element is used to provide backward compatibility for browsers that do not support the element, or if none of the source tags matched. The <picture> tag is similar to <video> and <audio>. We add different sources, and the first source that fits the preferences is the one that will be used.

What is the purpose of the IMG tag?

The <IMG> tag is used to incorporate in-line graphics (typically icons or small graphics) into an HTML document. This element is NOT intended for embedding other HTML text. For large figures with captions and text flow see FIG element.


1 Answers

You are missing several points. First, the best practices are not only about downloading, but about rendering as well, because if the whole page is downloaded for 3s but in require another 2s to be rendered, the user waits 5s, not 3s. I don't know best practice for putting images at the bottom (there is such for scripts), the best practice I know is to include width and height attributes so you do not block rendering while the image is being downloaded.

Another thing you are missing in your test is parallel downloading, as browsers limit the number of concurrent connections and you are testing with only one image. Make your tests with more images, or best - with a real web page, in order to have reliable results.

like image 108
Maxim Krizhanovsky Avatar answered Sep 18 '22 09:09

Maxim Krizhanovsky