-
Notifications
You must be signed in to change notification settings - Fork 20
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
Update picture source markup and make sizes attribute configurable from shortcode. #34
base: master
Are you sure you want to change the base?
Conversation
Update picture source markup and make sizes attribute configurable from shortcode.
Update picture source markup and make sizes attribute configurable from shortcode.
Hey man, great contribution. Sorry for the delay. In testing it locally here is what I'm seeing.
|
Hi Nick, This test: https://thirsty-aryabhata-198022.netlify.app/ has upper image sizes set to default ('100vw') and lower one ('(min-width: 500px) 500px, 100vw'). So I assume it would hint to browser that first image would be always scaled to the full width of screen and second one would be scaled to display width only when display is narrower than 500px and after that would be locked to 500px. There are images with widths 500, 100 and 1500px. Observations on first image
So chrome works as expected - loads all sizes for the first image depending on screen width and only 500px version for second one. Also chrome will stick to largest image loaded, firefox will keep loading images when screen width goes up or down. It might be that reformulating media conditions for sizes would affect this behaviour for firefox, hard to say, probably needs further research. Default sizes attribute could be specified in config but overridden also from shortcode as it's usually quite image and layout specific. There are other things as well that could be made configurable, like webp options as currently the output is quite heavy. Related mainly to this hard coded option nearLossless: true, but should deal with these separately probably |
In general images plugin works quite nicely for setting up responsive sizes for the same image.
'Art direction' would be too complicated to handle for such a general tool.
Have some proposals though. Current picture markup looks like this
🔗respimagelint complains about source elements:
So, with w descriptors and sizes attribute it should look like this instead ('data-' prefixes are added for 🔗vanilla-lazyload)
According to 🔗css-tricks x descriptors (1x 2x etc) only account for a small percentage of responsive images usage while using srcset / w + sizes accounts for around 85% of responsive images usage on the web.
As sizes attribute is too layout specific, it could have default value "100vw" and be configurable from shortcode as
As I understand, exact sizes are almost impossible to set by hand as each browser does its own thing:
Also 🔗respimagelint tool gives sizes suggestions that can be copied to shortcode from there.
No idea how this works but for example using it's suggested sizes on above the fold image:
effectively calmed down lighthouse complaints about images with inappropriate size.
Used resources