Closed bencbartlett closed 11 months ago
This has been annoying me, too. I think it occurs when the max-width of the largest image is smaller than the viewport width, e.g. on higher-resolution laptop/desktop screens.
An "ugly" fix is to change the last
For example, replacing the <source class="responsive-img-srcset" width="{{ i }}" media="(max-width: {{ i }}px)" srcset="{{ img_path | relative_url }}-{{ i }}.webp" >
command with:
{% if forloop.last %}
{% assign prev_index = forloop.index0 | minus: 1 %}
{% assign prev_width = site.imagemagick.widths[prev_index] %}
{% assign min_width = prev_width | plus: 1 %}
<source class="responsive-img-srcset" width="{{ i }}" media="(min-width: {{ min_width }}px)" srcset="{{ img_path | relative_url }}-{{ i }}.webp" >
{% else %}
<source class="responsive-img-srcset" width="{{ i }}" media="(max-width: {{ i }}px)" srcset="{{ img_path | relative_url }}-{{ i }}.webp" >
{% endif %}
There's probably a more elegant solution, so I haven't put this in a pull request! But it's a temporary fix...
I don't think I understand both the problem and your solution @AndLen. Can you explain it a little more?
This was confusing me too, think I figured it out though. The 'max-width' in the
@AndLen's solution makes it so that the original is never used, rather whenever the viewport is larger than the width of the second largest webp, the largest is used.
It's unclear if there would be a way to what you(and I) want, which is to load an image based on the expected rendered size of an image, and do it automatically/fully contained in figure.html. I'm looking into it, but if someone with more experience knows that'd be great.
Acknowledge the following
[For usage questions, please post in the Discussions instead of raising an issue.]
Describe the bug I have built a website using this template (which is wonderful by the way!) but the responsive images are not working the way I think they are intended to. Take a look at this page: https://bencbartlett.com/publications/. I have webp images for each publication thumbnail (example) but they are not correctly getting loaded by the browser and instead the full-size png images are loading. Try loading the linked publication page, open the inspection tools (cmd+opt+I) and go to the network tab and sort by waterfall plot, then do a hard refresh (cmd+shift+r) and you can see that none of the small webp images are loading. The viewports have a width of about 100px so the
-150.webp
images should load first.With
site.imagemagick
enabled, infigure.html
there is this snippet which I suspect is where the problem is but I have pretty limited web development experience so I'm not sure.To Reproduce Steps to reproduce the behavior:
Expected behavior When you do the above, one of the small webp images should load instead of the png.
Screenshots If applicable, add screenshots to help explain your problem.
System (please complete the following information):
Additional context Add any other context about the problem here.