How to Optimize Images for Websites and Core Web Vitals (LCP & CLS)
Unoptimized hero images are the #1 bottleneck behind slow Largest Contentful Paint (LCP) and jumping page layouts (CLS). On static sites hosted on Cloudflare Pages or GitHub Pages, disciplined asset optimization makes pages feel instantaneous.
1. Always Set Explicit width and height Attributes
When you include width="800" height="420" directly in HTML alongside CSS img { max-width: 100%; height: auto; }, browsers reserve the exact aspect-ratio box before a single image byte arrives—dropping Cumulative Layout Shift (CLS) to zero.
2. Lazy-Load Below-the-Fold Media (Never the Hero LCP Image!)
Add loading="lazy" to gallery cards, footer thumbnails, and blog post illustrations down the page. However, keep loading="lazy" OFF your primary above-the-fold hero banner so the browser fetches it immediately.
3. Prefer Inline or External SVG for Diagrams and Icons
- Export vector illustrations, logos, and UI icons as clean SVGs rather than 300 KB PNGs.
- Convert photographic assets to WebP under ~120 KB for full-width banners and ~40 KB for cards.
- Describe every meaningful image accurately in its alt attribute for accessibility and Google Images indexing.
Helpful Creator Tips
- Audit total transferred KB in Chrome DevTools Network tab throttled to Slow 4G—your homepage assets should ideally stay well under 500 KB.
- Combine static Cloudflare Edge caching with clean filenames.
Frequently Asked Questions
Related Guides
How to Compress Images Without Losing Too Much Quality
How resizing dimensions first and choosing the 78-85% quality sweet spot slashes file size before human eyes notice degradation.
How to Choose the Best Image Format: JPG vs PNG vs WebP vs AVIF vs SVG
Stop guessing between JPG, PNG, and WebP—use this clear cheat sheet for photography, UI graphics, and transparent icons.
Understanding Image Resolution: Pixels, Megapixels, DPI/PPI, and Aspect Ratios
Why pixel width x height controls screen sharpness, when 300 PPI actually matters for printing, and how megapixels add up.