Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Responsive Images on Android #239

Closed
Riczerq opened this issue Jul 13, 2020 · 12 comments
Closed

Responsive Images on Android #239

Riczerq opened this issue Jul 13, 2020 · 12 comments
Assignees
Labels

Comments

@Riczerq
Copy link

Riczerq commented Jul 13, 2020

Hello!

I tested the responsive.html on my android device and it is downloading the 800px image instead of the 480px. I have done different tests in other scenarios and it also gives the same result. It works properly on desktop.

My device esp:
Resolution: 1080x1920
DPR: 2.549999952316284
clientWidth: 424

@avivmu
Copy link
Contributor

avivmu commented Jul 14, 2020

Yeah you are right, the problem is with the elva-fairy image. I tested using both FF responsive mode, and Chrome responsive mode (from my computer). The one with Chris is loading the 480px width as you can see from the Network tab.

image

@Riczerq
Copy link
Author

Riczerq commented Jul 14, 2020

Exactly. Any ideas why this behavior happens with the elva-fairy image? Shouldn't the browser download the 480px wide image instead of the 800px image as it does on desktop mode?

@avivmu
Copy link
Contributor

avivmu commented Jul 15, 2020

I checked again and now I think it's working as expected.
When the browser calculates which image to use, it considers also the DPR - device pixel ratio, not only the available width.
Because your DPR is ~ 2.5, the max-width to use the smaller image is not 600px, but 600/2.5 = 240px. Since your device is more than that, it shows the bigger one.
You can test all of it from your computer using DevTools responsive mode.
DPR of 1 - works as expected:

  1. 600px - smaller image:
    image
  2. 601px - bigger one:
    image
    Also see this SO answer for more info
    I agree that this info about DPR should be mentioned in the tutorial to avoid future confusin. @chrisdavidmills your opinion?
    BTW if you no longer believe it's an issue please close it.

@Riczerq
Copy link
Author

Riczerq commented Jul 15, 2020

Thank you very much for answering!

I tried using a higher max-width (ex: (max-width: 3000px))to see if the problem was related to that, but it always showed the 800px image. Then, I tried by reducing the length used if the media query was fullfilled (ex: (max-width: 480px) 240px) that seemed to work with a 2.0 DPR. The problem is that I can't use the custom width I want on both mobile and desktop and the other problem is that in the 2.0 DPR example I can't use a width higher than 309. If I use a (max-width: 480px) 310px it no longer uses the 480px image in any resolution.

DPR 2.0 using (max-width: 480px) 309px - works as expected:

480px - downloading elva-fairy-480w

image

481px - downloading elva-fairy-800w

image

DPR 2.0 using (max-width: 480px) 310px - not working as expected

200px - downloading elva-fairy-800w

image

I don't know if it exist a better approach to make it work the same on both mobile and desktop, or if I'm missing something.

Full example:

<img srcset="elva-fairy-480w.jpg 480w, elva-fairy-800w.jpg 800w" sizes="(max-width: 480px) 309px, 800px" src="elva-fairy-800w.jpg" alt="Elva dressed as a fairy" />

@avivmu
Copy link
Contributor

avivmu commented Jul 18, 2020

I still think there is no bug. Try asking on SO so people can guide you where is your wrong assumption.

@Riczerq
Copy link
Author

Riczerq commented Jul 19, 2020

I don't think it's a bug either, but I can't understand the behavior with other DPRs. Thanks again for your help, I will try on SO. Should I close this issue?

@avivmu
Copy link
Contributor

avivmu commented Jul 20, 2020

You can wait until another one will step in to answer. It seems that the 309/310 settings are the browser threshold for these image widths for DPR 2.
If you will find more useful info on SO you can link to that thread and then close it.

@avivmu
Copy link
Contributor

avivmu commented Jul 24, 2020

@Riczerq any update on this? On FF 309px behaves the same as 310px (using always 800px)

@Riczerq
Copy link
Author

Riczerq commented Jul 24, 2020

Hi @avivmu ! No one has answered the question on SO yet. As soon as I find something or get an answer I will post it here.

@KooXme
Copy link

KooXme commented Feb 1, 2021

Index

@jacekkoziol
Copy link

Does anyone has any answer for this?

@caugner caugner added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Oct 10, 2023
@caugner caugner self-assigned this Oct 12, 2023
@caugner caugner added question and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Oct 12, 2023
@caugner
Copy link

caugner commented Oct 12, 2023

I took a look at this issue, and as was already pointed out:

  1. The DPI is taken into consideration when choosing the right size.
  2. The two photos on the page have different breakpoints:
    • The first photo has different sources for < 800px and >= 800px (or 400px with a DPR of 2).
    • The second photo has different sources for <= 600 px and > 600px (or 300px with a DPR of 2).

The examples is therefore working as expected (albeit slightly confusing), so I'm going ahead and close this issue as wontfix.

@caugner caugner closed this as not planned Won't fix, can't repro, duplicate, stale Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants