Logo
Banner
Story-teller
Icons
Non-text description
And loading them responsively & optimizedly is not easy...
Most popular
(Big in size)
Great for icon, animation
Most optimized
Not fully supported
New
Efficient & light-weight
Google LightHouse Metrics
srcset
Device sizes-based
Resolution-based
<img
srcset="example-480w.jpg 480w,
example-800w.jpg 800w"
sizes="(max-width: 600px) 480px,
800px"
src="example-800w.jpg"
alt="Example">
<img
srcset="example-320w.jpg,
example-480w.jpg 1.5x,
example-640w.jpg 2x"
src="example-640w.jpg"
alt="Example">
Choose the right
image
srcset
Pre-defined set of images to chose per device size/resolution
Less waste resource to download
Native solution
The Art Direction problem
<picture>
<source type="image/svg+xml" srcset="example.svg">
<source type="image/webp" srcset="example.webp">
<img src="example.png" alt="Example">
</picture>
Full-details image for large screen
Cropped/Shrink image (more focus) for small screen
Media query to define breakpoint
@media screen and (max-width: 16em) { ... }
@media screen and (max-width: 32em) { ... }
@media screen and (max-width: 41em) { ... }
CSS logical function (url(), image-set())
background-image: image-set(
url(icon1x.jpg) 1x,
url(icon2x.jpg) 2x
);
The answer is No
No cache image for CSS url() function (Chrome)
Download (preload) happens before CSS parsing
No EXACT match for device size (serve a 800w for a 700w or less)
High resolution image means heavy in bytes
All images downloaded despite of visibility on page
Different image types are meant for different usage
Using SVG for complex icons
Scalable Vector Graphics
Light-weight
Stylable using CSS
Semantic
Inline and accessibility-support
Using JPG for photos
Using PNG/WebP for better quality and compression ratios
<img loading="lazy" >
On-demand loading
Speed up initial page loading and rendering time
Image size compression without reducing quality (lossy/lossless)
Automatic run-time image optimisation with Cloudinary 😉
1200x800
1MB
1200x800
300kB
500x500
crop: thumb
500x500
{gravity: auto}
500x500
Hokusai effect
{radius: max, dpr: auto, art effect: hokusai}
500x500
Stamp effect
{e_red: 50, e_vectorize: 2:0.2 }
Use srcset and relative sizes to help browser to render the right image
Use <picture> for specifying images per device type only.
Use SVG for complex icons and animation
Lazy-load whenever you can
Leave the automation of image optimization to Cloudinary!
Senior Frontend Developer
Core maintainer of StorefrontUI
NuxtJS Ambassador
Everything about Frontend/Web