Skip to content

Instantly share code, notes, and snippets.

@verlok
Last active November 16, 2020 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save verlok/20b560ee07fb16b0c484fa7c204900e5 to your computer and use it in GitHub Desktop.
Save verlok/20b560ee07fb16b0c484fa7c204900e5 to your computer and use it in GitHub Desktop.
Capping image fidelity to 2x to minimize loading time on high-end mobile phones
<picture>
<!-- Landscape tablet / computers -->
<source media="(min-width: 1024px)"
sizes="(min-width: 1280px) 33vw, 50vw"
srcset="https://placehold.it/640 640w,
https://placehold.it/1024 1024w,
https://placehold.it/1280 1280w,
https://placehold.it/1440 1440w">
<!-- Portrait tablets -->
<source media="(min-width: 415px)"
srcset="https://placehold.it/768 2x" />
<!-- iPhone X, XR... -->
<source media="(min-width: 414px)"
srcset="https://placehold.it/828 2x" />
<!-- iPhone 6/7/8 -->
<source media="(min-width: 375px)"
srcset="https://placehold.it/750 2x" />
<!-- IE (src) + iPhone 12 Mini (capped) -->
<img src="https://placehold.it/1280"
srcset="https://placehold.it/720 2x"
alt="Batman Super-man and Wonder" />
</picture>
img {
width: 100%;
@media (min-width: 768px) {
width: 50%;
}
@media (min-width: 1280px) {
width: 33.3%;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment