-
-
Notifications
You must be signed in to change notification settings - Fork 753
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
Add Image for srcset and lazy loading #2103
Conversation
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.
wow
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.
Maybe rename ImageFromUrl to ScalableImage or something along these lines?
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.
Awesome PR! Thanks!
Only two things:
- naming: Since it's the embodiment of a how a Plone image should render, why not just call it
Image
? - scales: @tisto made some research based on our latest projects, and tried to push for a (new) standard scales for Volto:
Add modern image scales. kitconcept/kitconcept.volto#5
still pending, but we want to push it for the upcoming Volto integration package as default for Volto.
The rest is fine for me! Did you test it with a validator? Asko (@datakurre) was using this: https://ausi.github.io/respimagelint/ and did some research on this as well.
My experiment, which passed the validator, is here datakurre/my-volto-app@89c86ba I don't remember my use of But I recall that we had to hack Plone image sizes with unlimited heights, e.g.
to avoid browser getting scale, which required blocky upscaling 🤔 |
@datakurre thanks a lot!! I searched for it, but I couldn't find it! |
Updated the PR:
|
Preview of the loading with the placeholder. Heavily inspired by Gatsby image |
Sizes we use for the EEA website:
|
while defining the srcset we give all the needed info's by appending the size like On a 1x resolution screen it will be 800px as well as on a 2x resolution screen.
i don't why you think you need this, if you add the loading="lazy" attribute, the browser should be able to load lazy. Right now chrome will still load to fast all images, firefox and safari will save more data and only load images when you are getting close to them. https://www.ctrl.blog/entry/lazy-loading-viewports.html For Plone 6 classic UI we will probably stick with the browser defaults and just use loading="lazy". I guess when you add the srcset and the src attributes via the observer it should work, the browser can't load anything without either a src or a srcset.
not quite, the sizes attribute with out a media query defines the Intrinsic Size of the image, the same you can archive by setting the width attribute on the img tag. But it is true that the Browser is able to do the math for us, by calculating Intrinsic Size * screen resolution >> needed image size.
it depends if you want to change the Intrinsic Size for different viewports, most of the time that not needed. For example if our image is 250px and we want it to be almost full screen on a mobile device. In most cases it's not worth optimizing to much. https://css-tricks.com/a-guide-to-the-responsive-images-syntax-in-html/ |
also one thing i noted while playing around with my example page is that we need to set the height when we are using lazy loading or everything jumps arround 👯 |
sure! we could talk about this on discord. |
@MrTango i've investigated on 'jumping' images... and... i found that maybe it's to the miniature fault.... this is the reason for the 'jumpings' i think.. |
The jump will always happen when the browser does not have a hight to start with, before it lazy loads the image. |
it could be a solution.. but we don't know the real image height.. |
Image scaling discussion notes (Beethoven sprint 2022):
|
@MrTango @giuliaghisini modern browsers allow you to set the width and height params without "px", so you basically just set the aspect ratio. This allows the browser to fully render the image properly (avoid jumps) and at the same time provides full flexibility of the srcset attribute: https://www.smashingmagazine.com/2021/04/humble-img-element-core-web-vitals/#the-basics |
… width and height is provided
… width and height is provided
Today's testing showed that it does not matter much, what size we are putting into width/height attributes. So as long as we set width and height with the correct aspect ration, we can change it via CSS width and height="auto" as we want to. |
* chore: upgraded volto to 16 alpha 45 * chore: upgrades for volto16 * chore: upgraded mrs-developer * chore: upgrade dependencies * refactor: upgrade razzle config for razzle 4 * feat: added layout views i18n names * chore: removed passwordreset view backport * refactor: removed mrs-developer, deprecated @italia * chore: removed routes backports * chore: re-added our custom Image component * fix: config and sass dependencies * chore: updated locales * fix: styles after sass upgrade * chore: upgrade dependencies * chore: added test deployment config * fix: dockerfile * fix: cleanup rendering warnings * fix: workaround nested bootstrap/reboot * chore: bundlewatch removed * chore: volto16 update actions * fix: print styles compilation that broke reboot compilation * fix: test config * fix: tests * chore: customizationPaths * chore: bundle_size action * chore: remove duplicated action * chore: actions cleanup * fix: invalid comment * fix: view responsive image in gallery * fix: image intersectionobserver * fix: img responsive * fix: intersection observer simplified * chore: dockerfile + dockercompose * feat!: update volto * feat: node 16 / yarn 3 * ci: yarn 3 * ci: make * ci: yarn 3 * ci * ci: dockerfile * ci: dockerfile * ci: bundlesize * docs: docker compose update * feat: slick font removed * fix: missing image styles from plone/volto#2103 * chore: upgrade to volto 16.0.0 * build: upgraded docker base image to bullseye, cleaned up env vars * chore: removed old i18n pre-commit hook * build: use yarn 3 * build: commit hooks dependencies Co-authored-by: mamico <[email protected]>
Superseded by #3337 |
Features:
Added code and tests, refactored components with images to use ImageFromUrl
This should improve performances avoiding loading heavy images if not needed.