0
0
Bootsrapmarkup~8 mins

Responsive images in Bootsrap - Performance & Optimization

Choose your learning style9 modes available
Performance: Responsive images
HIGH IMPACT
Responsive images affect page load speed by delivering appropriately sized images for different screen sizes, reducing data usage and improving loading times.
Serving images that fit the user's device screen size
Bootsrap
<img src="small-image.jpg" srcset="small-image.jpg 480w, medium-image.jpg 768w, large-image.jpg 1200w" sizes="(max-width: 600px) 480px, (max-width: 900px) 768px, 1200px" class="img-fluid" alt="Example image">
Browser selects the best image size for the device, reducing download size and speeding up load.
📈 Performance GainReduces image download size by up to 80% on small devices; improves LCP
Serving images that fit the user's device screen size
Bootsrap
<img src="large-image.jpg" class="img-fluid" alt="Example image">
Loads a large image on all devices, wasting bandwidth and slowing down load times on small screens.
📉 Performance CostBlocks rendering longer due to large image download; increases LCP time
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Single large image for all devicesMinimal1 reflow on image loadHigh due to large image decode[X] Bad
Responsive images with srcset and sizesMinimal1 reflow on image loadLower due to smaller image decode[OK] Good
Rendering Pipeline
Responsive images reduce the time spent in the loading and painting stages by delivering smaller image files tailored to the device's screen size.
Network Loading
Layout
Paint
⚠️ BottleneckNetwork Loading due to large image files
Core Web Vital Affected
LCP
Responsive images affect page load speed by delivering appropriately sized images for different screen sizes, reducing data usage and improving loading times.
Optimization Tips
1Always use srcset and sizes attributes to serve images tailored to screen size.
2Avoid loading large images on small devices to reduce load time and data usage.
3Test responsive images by resizing the browser and checking image file sizes in DevTools.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of using responsive images with srcset?
AIt delays image loading until user interaction.
BIt automatically compresses images on the server.
CLoading smaller images on small screens reduces data usage and speeds up page load.
DIt increases image quality on all devices.
DevTools: Network
How to check: Open DevTools, go to Network tab, reload page, filter by Images, and check the size of images loaded on different screen widths.
What to look for: Look for smaller image file sizes on smaller screen widths indicating responsive images are working.