Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Responsive Images using <picture> and srcset/sizes

Responsive Images using <picture> and srcset/sizes

Matt Steele

July 02, 2014
Tweet

More Decks by Matt Steele

Other Decks in Programming

Transcript

  1. http://httparchive.org/trends.php#bytesTotal&reqTotal Total Page Weight File Size (KB) 1400 1550 1700

    1850 July August September October NovemberDecember January February March April May June
  2. http://httparchive.org/trends.php#bytesTotal&reqTotal Total Page Weight File Size (KB) 1400 1550 1700

    1850 July August September October NovemberDecember January February March April May June 1485kb 1521kb 1551kb 1590kb 1614kb 1701kb 1681kb 1710kb 1728kb 1762kb 1775kb 1808kb
  3. 72% Responsive sites serve the same content to desktop &

    mobile http://www.guypo.com/uncategorized/real-world-rwd-performance-take-2/
  4. <picture> <source media="(min-width: 1000px)" srcset="large.webp" type="image/webp"> <source media="(min-width: 1000px)" srcset="large.png">

    <source media="(min-width: 640px)" srcset="medium.png"> <img src="fallback.png"> </picture>
  5. Rendered Size For this MQ: Image renders this big sizes="(min-width:

    1024px) 300px, (min-width: 640px) 50vw, 100vw"
  6. Rendered Size For this MQ: Image renders this big Default

    sizes="(min-width: 1024px) 300px, (min-width: 640px) 50vw, 100vw"
  7. <img src="small.jpg" alt="A responsive image" srcset="large.jpg 1200w, medium.jpg 640w, small.jpg

    320w" sizes="(min-width: 1024px) 300px, (min-width: 640px) 50vw, 100vw">