This is an image srcset generated by Gatsby:
<source type="image/webp" srcset="
/static/be21c7dd0d11c74c18530fc39aefa922/10917/mailboxes.webp 200w,
/static/be21c7dd0d11c74c18530fc39aefa922/21f2d/mailboxes.webp 400w,
/static/be21c7dd0d11c74c18530fc39aefa922/fdc6a/mailboxes.webp 800w,
/static/be21c7dd0d11c74c18530fc39aefa922/e7f3d/mailboxes.webp 1200w,
/static/be21c7dd0d11c74c18530fc39aefa922/faacb/mailboxes.webp 1600w,
/static/be21c7dd0d11c74c18530fc39aefa922/acdd2/mailboxes.webp 1800w"
sizes="(max-width: 800px) 100vw, 800px">
My image is displayed in a container that is at most 800px wide, so this is how I would prefer the browser to choose:
if screenWidth > 400 then choose 800w
if screenWidth > 200 then choose 400w
else choose 200w
However, the browser is actually always choosing the largest possible image (even if I resize the browser to 200 width).
I believe the problem is here:
sizes="(max-width: 800px) 100vw, 800px"
There should be like ~3 conditions, right? Instead there is only 1 condition. I'm not sure I'm even able to interpret what this condition is trying to ask the browser to do.
Below is my GraphQL code:
edges {
node {
excerpt
fields {
slug
prefix
}
frontmatter {
title
tags
cover {
children {
... on ImageSharp {
fluid(maxWidth: 800, maxHeight: 360, traceSVG: { color: "#f9ebd2" }) {
...GatsbyImageSharpFluid_withWebp_tracedSVG
}
}
}
}
}
}
}
The fragment ...GatsbyImageSharpFluid_withWebp_tracedSVG
generates srcset
and sizes
. In the documentation there isn't anything I could do to affect how they are generated. However, I could potentially manipulate them at a later point:
<Picture fluid={fluid} />
Should I manipulate fluid.sizes
at this point, or is there a less dirty way to fix the srcset?