Why images are the main performance problem
On average, images account for 50-60% of a web page's total weight. A photo taken with a modern phone can weigh 4-8MB. Without optimization, that image can wreck your LCP and make the site feel slow even on good hosting.
Modern formats: WebP and AVIF
WebP: developed by Google, it's supported by every modern browser. It compresses images 25% to 35% better than JPEG with no visible loss of quality. It's the minimum you should be using today.
AVIF: newer and more efficient. It compresses 50% to 60% better than JPEG. Browser support is already broad. The recommended strategy is to serve AVIF with WebP and JPEG fallbacks using the picture element.
Responsive images: delivering the right size
There's no point loading a 1920px image on a phone with a 400px screen. The srcset attribute lets you specify multiple versions of an image so the browser picks the most appropriate one. Use 400w, 800w, and 1200w versions to serve the right size for each device.
Lazy loading: don't load what isn't visible
The loading='lazy' attribute keeps images outside the initial viewport from loading until the user gets close to them. It's one line of code that can significantly improve initial load time. Never lazy-load the hero image: it needs to load immediately.
Always set dimensions
Always setting the width and height attributes on images prevents CLS. Without dimensions, the browser doesn't know how much space to reserve, and content jumps when the image loads, which directly affects Core Web Vitals.
Tools for optimizing images
Squoosh (squoosh.app) for manual optimization with a real-time preview. ImageMagick for batch processing. On WordPress, plugins like ShortPixel or Imagify automate the process. In custom projects, the Sharp library for Node.js is the fastest.