5
I do not know if the title of the question is clear, I will try to explain as clearly as possible. I’m studying about responsive websites and try my best not to use large images so the site doesn’t slow down. I saw that I can create versions of different sizes of an image and depending on the size of the device, place them on an object.
So instead of loading a 5000px wide image and making it resize according to the size of the element this way:
#elemento {
background-image:url('imagem.png'); /* Imagem com 5000px de largura */
background-size:100%;
width:100%;
}
I can do it:
@media screen and (max-width: 600px) {
#elemento {
background-image:url('imagem600.png'); /* Imagem com 600px de largura */
}
}
@media screen and (max-width: 900px) {
#elemento {
background-image:url('imagem900.png'); /* Imagem com 900px de largura */
}
}
@media screen and (max-width: 1300px) {
#elemento {
background-image:url('imagem1300.png'); /* Imagem com 1300px de largura */
}
}
The question
When having a device with a width of 900px, only the corresponding image will load or all will be downloaded? If all are downloaded, there is some way for the user who has a small device not to have to download a very giant image unnecessarily?
Only the "downloaded" image shown in
@media
which corresponds to the visitor’s screen because only the contents of that@media
is going to be read!– Zuul
So the image will only be downloaded if a user using a computer resizes the window? Therefore, there is the possibility of for example, someone who is accessing the site by a mobile phone download 5mb in images, right?
– Rafael Almeida
..... Right! .....
– Zuul
The dots in the previous comment is only because the systems do not let comment with so few characters. This comment is just to piss people off!
– Zuul
Thank you very much, at least with this I should not worry anymore. Put as an answer to mark it!
– Rafael Almeida
I will reply, I am elaborating the subject in greater detail to clarify some things associated with this theme. However also other answers may arise to better clarify the doubt :)
– Zuul