Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: AdaptiveMedia: wrong image selection for device size
On a page we display articles. Each article begins with an image. To increase performance we configured adaptive media and also created three image resolutions. The mentioned article images take 302x170 px on desktop devices. Unlike what I assumed, the default image with high resolution is loaded and not the optimized one with a maximum width of 305 pixels (one of the three adaptive media rules). Why is that?
Attachments:
Jürgen Untch:
...Unlike what I assumed, the default image with high resolution is loaded and not the optimized one with a maximum width of 305 pixels (one of the three adaptive media rules). Why is that?
The <img> element in the <picture> element only depicts the fallback, and the browser shall pick one of the elements from the <source> elements. Observe what the browser actually requests in the Network tab - The markup is as I expect it, and you it's up to the browser to request the correct image.
Because Adaptive Media is deeply flawed.
It doesn't insert the image that fits best, it always just uses the device width to determine the width of the image. (As can be seen with the media queries). The following feature request explains the issue in detail:
https://issues.liferay.com/browse/LPS-94984
It doesn't insert the image that fits best, it always just uses the device width to determine the width of the image. (As can be seen with the media queries). The following feature request explains the issue in detail:
https://issues.liferay.com/browse/LPS-94984
@Olaf The desktop browser always loads the fallback image on the page.
Please look at the media rules in the source elements.
Rule 1 says "(max-width: 128px)" -> This image is loaded on screens with less than 128px width
Rule 2 says: "(max-width: 305px) and (min-width: 128px )". If rule one isn't met, this image is loaded on screens with less than 305px width.
In a real world situation both of these rules are useless since (except for some really special cases) there are no devices with less than 360px width.
Rule 3 is the first relevant one. It loads a 1000px image on devices with a screen width of 305 - 1000px. While this matches several smartphones, it is a wasteful rule. It loads a 1000px image on a device with 360px width.
Since there are no further rules and desktop monitors usually have more then 1000px width, on desktop you will always see the fallback image.
Rule 1 says "(max-width: 128px)" -> This image is loaded on screens with less than 128px width
Rule 2 says: "(max-width: 305px) and (min-width: 128px )". If rule one isn't met, this image is loaded on screens with less than 305px width.
In a real world situation both of these rules are useless since (except for some really special cases) there are no devices with less than 360px width.
Rule 3 is the first relevant one. It loads a 1000px image on devices with a screen width of 305 - 1000px. While this matches several smartphones, it is a wasteful rule. It loads a 1000px image on a device with 360px width.
Since there are no further rules and desktop monitors usually have more then 1000px width, on desktop you will always see the fallback image.
Thanks Christoph for the clear response. So liferays adaptive media rules only care about the actual screen resolution (width and height) of the device and not the size an image needs to fit in a container.Is there a way in Liferay to get the minified image on the articles overview page regardless of the screens resolution? I only need the full-sized image if I access the details page of a concrete article.
If you have a freemarker template or a portlet: It should be possible to fetch the possible image preview urls somehow through the api and insert it manually. But I never tried that, it looked awfully complicated to do that and I have developed my own solution instead of fiddling with Adaptive Media.
There's also marketplace plugins that go in that direction, maybe one of them is useful.
There's also marketplace plugins that go in that direction, maybe one of them is useful.
@ChristophI came accross https://help.liferay.com/hc/en-us/articles/360018161551-Finding-Adapted-Images. I will try to do it that way.
We have done this in one of my projects.
You can create a Service and use it in your FTL.
And cherry on the cake, you can add an asynchronous load of the image like Lozad.js
With that, you will load the image only if it is visible and it will be the small image.
But be careful to find an image because adaptive media create the image only if it is possible.
Example, if my client add a small image 200px length, and I have a adaptive rule to reduce to 300px length, the adaptive media will not be generated. I must use the original image.
Eric.
You can create a Service and use it in your FTL.
And cherry on the cake, you can add an asynchronous load of the image like Lozad.js
With that, you will load the image only if it is visible and it will be the small image.
But be careful to find an image because adaptive media create the image only if it is possible.
Example, if my client add a small image 200px length, and I have a adaptive rule to reduce to 300px length, the adaptive media will not be generated. I must use the original image.
Eric.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™