The perfect image is often different depending on the screen size. The following example will get two different sizes, depending on the screen size. Try resizing the screen and watch the network (F12) to see when the other sizes are loaded.
To see the currentSrc change, make the window narrow, reload, and then drag it to become larger.
image src should appear here
@inherits Custom.Hybrid.Razor14
@{
var imgPath = App.Path + "/assets/img-resize";
}
<picture>
<source type="image/webp" srcset="@imgPath/koi-2000.webp 2000w,
@imgPath/koi-1000.webp 1000w,
@imgPath/koi-500.webp 500w,
@imgPath/koi-250.webp 250w,"
sizes="(max-width: 300px) 250px, (max-width: 600px) 500px, (max-width: 1200px) 1000px, 2000px">
<source type="image/png" srcset="@imgPath/jellyfish-2000.jpg 2000w,
@imgPath/jellyfish-1000.jpg 1000w,
@imgPath/jellyfish-500.jpg 500w,
@imgPath/jellyfish-250.jpg 250w,"
sizes="(max-width: 300px) 250px, (max-width: 600px) 500px, (max-width: 1200px) 1000px, 2000px">
<img loading="lazy" class="img-fluid" src="@imgPath/jellyfish-1000.jpg" alt="Picture srcset demo">
</picture>