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

Is Gatsby-image supposed to serve larger images on mobile than on desktop? #8100

Closed
mixolydian251 opened this issue Sep 12, 2018 · 14 comments
Closed
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@mixolydian251
Copy link

Summary

I was taking a peek at the images served using gatsby-image and noticed that images that are served to mobile are larger than the images served to the desktop browser. Is this a bug, or a limitation on mobile devices?

Relevant information

I first noticed this on my own site, but saw that the gatsby-image demo was producing the same issue.

Steps to reproduce

  • Go to gatsby-image demo
  • Open developer network tool and load the site
    screen shot 2018-09-12 at 6 40 51 pm
  • Simulate mobile through dev tools and load the site
    screen shot 2018-09-12 at 6 41 33 pm

Environment (if relevant)

File contents (if changed)

gatsby-config.js: N/A
package.json: N/A
gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A

@kakadiadarpan
Copy link
Contributor

Hi @mixolydian251, for me it's giving a larger sized image for the desktop and smaller sized for the mobile. Please check the screenshots attached below.

Desktop:
screen shot 2018-09-13 at 9 45 02 am

Mobile:
screen shot 2018-09-13 at 9 45 41 am

@kakadiadarpan kakadiadarpan added the type: question or discussion Issue discussing or asking a question about Gatsby label Sep 13, 2018
@mixolydian251
Copy link
Author

mixolydian251 commented Sep 13, 2018

hmm interesting.. Which OS are you running?

I am running Chrome on MacOS Sierra, and have a team member running a linux dist that has seen the same issue.

Here is another live screenshot of the issue on my end.

gatsby_image

Looks like I am getting your desktop sizes on mobile, and smaller sizes on my desktop version?

@kakadiadarpan
Copy link
Contributor

I'm on MacOS High Sierra.

@kakadiadarpan
Copy link
Contributor

cc @pieh @m-allanson

@mixolydian251
Copy link
Author

Although it looks like on on Firefox I am getting different results.

First image is smaller on mobile, while 2nd stays the same.

gatsby_image

@stefanprobst
Copy link
Contributor

This is very probably because of Device Pixel Ratio. What happens in Firefox when you select a specific device?

@mixolydian251
Copy link
Author

Yes, looks like DPR is causing the image size to scale up as the ratio increases. From what I am seeing mobile devices tend to have higher ratios.

On my screen it looks like the pixel ration is close to 1. When simulating mobile DPR increases and changes when switching devices. Thus the increase in file size?

@kakadiadarpan What device are you simulating in devtools? If you are using a retina display then simulating something with a lower DPR, could possibly be why we are getting different results?

@kakadiadarpan
Copy link
Contributor

@mixolydian251 I have an MBP with a resolution of 2560 x 1600, and using an iPhone 7 plus for simulation which has a DPR of 3.0.

@fk
Copy link
Contributor

fk commented Sep 14, 2018

Hey y'all! 👋I wrote this last night while not really being awake anymore (and then forgot to post it ;-)), so take this with caution 🙏

FWIW, my gut says everything is working as expected 🤞

@CanRau
Copy link
Contributor

CanRau commented Oct 1, 2018

Just ran a Chrome Audit which mentioned a too large image on mobile (1280px)
and figured it might be due to the sizes attribute

<picture>
  <source
    srcset="/static/banner-5be5e.jpg 320w,
          /static/banner-bd363.jpg 640w,
          /static/banner-2f993.jpg 1280w,
          /static/banner-ed8a9.jpg 1920w,
          /static/banner-04caa.jpg 2560w,
          /static/banner-9bee0.jpg 3840w,
          /static/banner-95454.jpg 4000w"
    sizes="(max-width: 1280px) 100vw, 1280px"
  >
</picture>

Is this the best setting?
Uh, it's from a fluid query and it's the header background so full screen
Also, there is currently no way overriding the sizes attribute? I'm at least getting an error, that it expects an object and not a string even though this gatsby-image/src/index.js#L453 sounds pretty stringy to me?

@stefanprobst
Copy link
Contributor

@CanRau I think the issue is not so much the sizes but the default breakpoints for srcSet. In your example you would get the 1280px image also for viewports with 641px width. Hopefully #8825 will help here.

@CanRau
Copy link
Contributor

CanRau commented Oct 5, 2018

Right! Didn't really checked srcSet, thanks for the hint and the link, the PR looks promising 👍

@CanRau
Copy link
Contributor

CanRau commented Oct 18, 2018

I would say it's better now thanks to #8825 🎉

@LekoArts
Copy link
Contributor

Closing this issue as answered. If you need more help, please reach out to us!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

6 participants