-
Notifications
You must be signed in to change notification settings - Fork 30
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
The Portrait Immersive Main Media Width Problem #2205
Conversation
@paperboyo @sndrs @JamieB-gu @mxdvl thoughts? |
Size Change: +1.07 kB (0%) Total Size: 717 kB
ℹ️ View Unchanged
|
Interestingly on AR it looks like we've come up with a similar solution to the frontend one you described above (i.e. using On a related note, I've also noticed that our
Are you saying this solution is temporary until you introduce IR into DCR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really comprehensive! great work!
Related to (as Lightbox would be another portrait situation): guardian/frontend#12216 (comment)
👏
👏 👏 Apart from using Picture (being able to prevent phones from downloading higher res for desktops is most important in immersive, as we currently satisfy quite high quality desktop displays), I wonder what more we could do. If we would to forego being able to resize the browser (and a picture following fluidly) only on phones and be OK with another request when readers change orientation (how often?), maybe we could use the resizer to actually cut off sides of these (with some leeway for differently ratioed phone displays)? That should shave a lot for phone-only downloads. Unless I haven’t thought of something? Whenever we gave any thought to Grid supporting “mobile” crops explicitly, we always ended up thinking that setting point(s) of interest would be preferable to actually providing (and requiring users to set) two different physical crops (art direction-like). But whatever we will choose one day (if we ever do it), currently all these are just always cropped off equally relative to the image centre. |
Yes, we've taken the approach in DCR of seeting some short term goals of improving image quality to give readers a better experience - which we're doing by using an |
This sounds like a good trade off. Small images giving us a performance win vs. unexpected behaviour when resizing the screen. +1 for the perf. gain here, screen resizing must be very rare (outside the second Floor). An automated solution like this would obviously be easier that asking people to take additional steps in Grid but there's possibly a lot of benefit to having a human choose where that portrait crop happens? I guess though that Viewer is the sanity check here so any strange mobile cropping will be seen at this stage. |
I think so. Especially on mobile! But this is really unrelated directly to the second point (sorry for introducing confusion). Currently all images coming from Grid are the same, just of different size. DCR/AR/IR could unilaterally decide to cut off invisible sides (if only for mobile). And nobody would loose anything and only gain some pocket change from smaller phone bill (even orientation change probably fires off another request?). Regarding us supporting aided multiple-ratio cropping for fluid scenarios one day: yes, users now sometimes crop source images in Grid several times, before they arrive at the satisfactory result on different ratios (doesn’t help that they all seem to think immersive must be 5:3 for some unknown reason!). I only mentioned it, because then we would need stop this arbitrary cropping off sides relative to the centre, described in the previous paragraph, and start doing it relative to these point(s) of interest that arrived through CAPI. I give us 5 years, though, so a non-issue. |
👋 to anyone reading this in 5 years |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paperboyo @sndrs @JamieB-gu @mxdvl thoughts?
Could we use the same (orientation: portrait)
and use that set the size to 167vh
, assuming 5:3 is the most common ratio? It seems that this change would limit the resolution of images to 1300px even though they stretch to the whole viewport on large devices.
(orientation: portrait) 167vw,
100vw
/** | ||
* mobile: 320 | ||
* mobileMedium: 375 | ||
* mobileLandscape: 480 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how accurate is that, nowadays?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not very, the name is certainly confusing for me. We design to it though so it would be hard to remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The names are somewhat arbitrary. We need to specify breakpoints somewhere - we could probably name them 1-7 if we wanted to 🤷♂️.
src/web/components/Img.tsx
Outdated
? ` | ||
(min-width: ${breakpoints.leftCol}px) 1600px, | ||
(min-width: ${breakpoints.desktop}px) 1900px, | ||
(min-width: ${breakpoints.tablet}px) 1900px, | ||
(min-width: ${breakpoints.phablet}px) 1600px, | ||
(min-width: ${breakpoints.mobileLandscape}px) 1300px, | ||
(min-width: ${breakpoints.mobileMedium}px) 900px, | ||
1300px | ||
` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? ` | |
(min-width: ${breakpoints.leftCol}px) 1600px, | |
(min-width: ${breakpoints.desktop}px) 1900px, | |
(min-width: ${breakpoints.tablet}px) 1900px, | |
(min-width: ${breakpoints.phablet}px) 1600px, | |
(min-width: ${breakpoints.mobileLandscape}px) 1300px, | |
(min-width: ${breakpoints.mobileMedium}px) 900px, | |
1300px | |
` | |
? ` | |
(orientation: portrait) 167vw, | |
100vw | |
` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be clear, I think (orientation: portrait) 167vw
above should read as (orientation: portrait) 167vh
(vh
) so I'm leaving this commit suggestion alone and I'll push this change up manually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to note that while it’s definitely true that most main medias are 5:3, there is nothing stopping them being any ratio. As I understand, this (167vh
) will control the number of steps, so if it’s gonna be off, nothing terrible will happen. Still, curious what Kylie’s gonna look like.
I think that the default to |
This is an inspired idea. It's so simple but does exactly what we want! 👏 The reason that I used varying sizes at different breakpoints is because device screen ratios actually vary quite a bit but by utilizing the viewport height to set the desired width you nicely sidestep that problem. I also ❤️ how the code is so much simpler using this approach. However, I tried it out locally and it seems to be returning the expected images in Chrome but Firefox is stubonly set on always returning the largest image so I want to investigate this some more. |
Firefox again? Maybe it’s somehow related to this? |
I think you're right. I think it was using an image from it's cache rather than fetching a new one. Seems to have fixed itself now though after I disabled the cache 🎉 . I've read about these kind of problems when testing images like this. Each browser has implemented the spec in their own way and there are some factors which can make things unpredicable (for instance, I think Chrome will choose a different image based on network conditions). |
Oh, boo. I thought there is something in common to both behaviours of Firefox. The other one still consistently chooses 445px in place of 620px cache or not. Nevermind, here was hoping, this is unrelated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the clarity around portrait mode triggering a large image 😉
Is this the "Art Direction" problem?
How is |
Not AFAIU. Kinda opposite of it. Art Direction means you are explicitly providing a different image for mobile. Here, knowing upfront that you are displaying this image on mobile, you just blindly cutting off the parts you know aren’t going to show up. And you keep quiet about it in front of your Art Director, coz you know he won’t even notice. IOW, the image will look exactly the same but will weigh less. Needs some leeway to satisfy different phone ratios. And probs mobile only, coz on desktop Art Director may accidentally resize the window and notice you not telling him. |
What does this change?
This is a proposal for discussion around a problem where immersive main media images are being chosen by the browser poorly on portrait devices. This happens because we size the main media content based on 100vh but for portrait aspect ratios this results in us loading much smaller images than we need.
What was done in Frontend?
This problem has already been raised, discussed and solved 5 years ago, see:
guardian/frontend#12811
and then
guardian/frontend#12847
That work resulted in this excellent code:
where
ratioDouble
isWhy are we not doing the same thing?
We must ensure that this work is not lost when transitioning to
image-rendering
but before we adopt the IR picture tag approach, this PR applies a simpler method via theimg
tag.So instead of using an
imageRatio
based on an imagesheight
andwidth
to calculate the correct width to set insizes
this PR is simply using the viewport height and an assumed image ration of 5:3 to decide what width to ask for.Shouldn't we be more explicit?
There's a case for being more chill. The argument goes along the lines of: it's hard to get this right and when you aim for absolute perfection it's very easy to make mistakes because the logic is complex. Keeping it chill makes it easy to see what's going on.
Of course, we can do better and we should. Even small perf gains at scale are worth the extra complexity. But a staged approach to getting there, starting off simple, might be nice?