srcset and Connection-Aware Image LoadingMobile: No modals, just scrolling gallery (filmstrip)
Desktop: Gallery grid + modals
Your goals:
srcset decisionsBased on testing with network throttling, browsers prioritize:
Your observation is correct: Browsers may load high-res images even on slow connections if the viewport/pixel density suggests it.
srcset Actually Doessrcset tells the browser “here are your options,” but the browser decides based on:
The problem: Browsers don’t reliably check connection speed, so you can’t count on it.
srcset for Modalssrcset)<!-- Gallery: Always fast, always low-res -->
<img
src="https://photos.alabut.com/shelterisland/tower-vertical-600w.avif"
alt="Tower vertical">
Why:
<source> Variants in <picture>Gallery cards still use the simple <img> above, but desktop modals follow the pattern documented in docs/photos-html.md: every modal is a <picture> whose <source> tags carry the width variants, while the <img> remains a lightweight fallback. That keeps the heavier 1200–3600 px files from downloading until the modal is actually opened.
<picture>
<source
media="(min-width: 769px)"
type="image/avif"
srcset="https://photos.alabut.com/shelterisland/tower-vertical-600w.avif 600w,
https://photos.alabut.com/shelterisland/tower-vertical-900w.avif 900w,
https://photos.alabut.com/shelterisland/tower-vertical-1200w.avif 1200w,
https://photos.alabut.com/shelterisland/tower-vertical-2400w.avif 2400w,
https://photos.alabut.com/shelterisland/tower-vertical-3600w.avif 3600w"
sizes="800px">
<img
src="https://photos.alabut.com/shelterisland/tower-vertical-600w.avif"
alt="Tower vertical"
class="modal-image"
fetchpriority="low"
decoding="async">
</picture>
Why sizes="800px":
docs/photos-html.mdTrade-off:
srcset, But with sizes to Guide Decisionssrcset with sizes to Force Low-Res<!-- Gallery: Tell browser image is small, so it picks low-res -->
<img
srcset="https://photos.alabut.com/shelterisland/tower-vertical-600w.avif 600w,
https://photos.alabut.com/shelterisland/tower-vertical-3600w.avif 3600w"
sizes="250px"
src="https://photos.alabut.com/shelterisland/tower-vertical-600w.avif"
alt="Tower vertical">
Why sizes="250px":
<picture> + <source>Even in this approach the modal structure mirrors the snippet above: wrap your variants in <source> so they don’t download until the modal shows. The sizes="800px" guidance still applies.
srcset ModalsPros:
srcset or sizes in gallery)Cons:
srcset Everywhere with sizesPros:
sizes="250px")srcset)Cons:
Hardcode low-res for gallery, use srcset for desktop modals only.
Why:
srcset there makes sense<!-- Gallery: Always fast -->
<img
src="https://photos.alabut.com/shelterisland/tower-vertical-600w.avif"
alt="Tower vertical">
<!-- Desktop Modal: Let browser choose (with awareness it may not check connection speed) -->
<img
srcset="https://photos.alabut.com/shelterisland/tower-vertical-600w.avif 600w,
https://photos.alabut.com/shelterisland/tower-vertical-3600w.avif 3600w"
sizes="800px"
src="https://photos.alabut.com/shelterisland/tower-vertical-3600w.avif"
alt="Tower vertical">
sizes in ModalsThe sizes="800px" in modals tells the browser:
sizes: Browser assumes 100vw (could be 1920px), might load 3600w even when not neededsizes="800px": Browser knows it needs ~800px, makes more informed decisionBut: Browser still may load 3600w on slow connections if it prioritizes quality over speed (which is common).
srcset with sizes="800px" (high-res when appropriate)This approach prioritizes speed where it matters most (gallery) and allows quality where users expect it (modals), while acknowledging browser limitations.