timse / srcset-loader

Flexible srcset-loader for webpack
46 stars 14 forks source link

'ratio' should be promoted #18

Open tremby opened 6 years ago

tremby commented 6 years ago

In my opinion ratio shouldn't be at img.placeholder.ratio but instead promoted to img.ratio. It's a property of the original image, not just of the placeholder, and is useful even when not using the placeholder.

For example, browsers like when width and height attributes are given, since it means the page can be laid out sooner. This can be done with the ratio and a reference size:

<!-- current ratio implementation (ratio=height/width) -->
<img ... width="250" height="{{Math.round(250 * img.placeholder.ratio)}}">

<!-- ratio implementation from #16 (ratio=width/height) -->
<img ... width="250" height="{{Math.round(img.placeholder.ratio / 250)}}">

I think this should be possible even if the placeholder is not being calculated.