Performance: Why media components enhance content
Media components affect page load speed and visual stability by adding images or videos that can delay content rendering if not optimized.
<img src="small-optimized-image.webp" alt="Description" loading="lazy" width="300" height="200">
<img src="large-image.jpg" alt="Description">
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Large unoptimized image | Low | Multiple (due to layout shifts) | High (large repaint area) | [X] Bad |
| Optimized image with lazy loading | Low | Single (initial layout) | Low (small repaint area) | [OK] Good |
| Full video iframe embed | Medium | Multiple (heavy layout) | High (complex paint) | [X] Bad |
| Video placeholder with deferred load | Low | Single | Low | [OK] Good |
media to create a media object container.media-container, media-object, and media-box are not standard Bootstrap classes.<div class="media">
<img src="img.jpg" class="mr-3" alt="Image">
<div class="media-body">
<h5>Title</h5>
<p>Description text here.</p>
</div>
</div>media class arranges the image and text side by side, with the image on the left by default.img with class mr-3 adds margin to the right, spacing it from the text in media-body which contains the title and description.<div class="media">
<img src="photo.png" alt="Photo">
<div class="media-body">
<h4>Heading</h4>
<p>Some text here.</p>
</div>
</div>mr-3 to the image for spacing between image and text.media-body is correctly inside media, the image tag is valid without self-closing slash in HTML5, and alt should describe the image, not be empty.mr-3 on the image for spacing. -> Option Dmr-3 on the image for spacing. [OK]flex-row-reverse to the media container reverses the order, placing the image on the right and text on the left.media-body is for text container, and container and row are unrelated to media component layout.media class and add flex-row-reverse to reverse the order. -> Option BPass the test and this pattern moves unknown