Images are often among the largest resources downloaded by a webpage.
As frontend developers, we spend time optimizing JavaScript bundles, caching strategies, and CSS delivery. But an oversized hero image can still hurt loading performance.
Here's a practical image optimization workflow that developers can use.
1. Start With Image Dimensions
Before compressing an image, ask a simple question:
Does this image need to be this large?
For example, displaying a 4000-pixel-wide photograph inside an 800-pixel-wide content area may waste bandwidth.
Resize images appropriately and provide responsive variants when needed.
2. Choose the Right Format
Different formats serve different purposes:
- JPEG: Useful for photographs.
- PNG: Suitable for graphics requiring lossless quality or transparency.
- WebP: Supports efficient lossy and lossless compression.
- AVIF: Can provide strong compression efficiency, depending on the content and encoding settings.
Always test visual quality rather than assuming one format is best for every image.
3. Compress Images Before Deployment
Image compression should be part of your publishing or deployment workflow.
For a quick manual optimization step, you can use an online tool such as Klyvero Labs Image Compressor.
The important thing is to compare the compressed result against the original before using it in production.
4. Implement Responsive Images
HTML supports responsive image delivery using srcset and sizes.
<img
src="/images/photo-800.webp"
srcset="
/images/photo-400.webp 400w,
/images/photo-800.webp 800w,
/images/photo-1200.webp 1200w
"
sizes="(max-width: 600px) 100vw, 800px"
width="800"
height="500"
alt="Descriptive image text"
/>
This helps browsers select an appropriate image resource for the available display space.
5. Optimize for Core Web Vitals
Image optimization can influence Largest Contentful Paint (LCP), particularly when the largest visible element is an image.
Additional considerations include:
- Avoid unnecessarily lazy-loading an above-the-fold LCP image.
- Set image dimensions to reduce layout shifts.
- Use efficient caching.
- Consider
fetchpriority="high"for the main LCP image when appropriate. - Test using Lighthouse and PageSpeed Insights.
6. Measure Before and After
Compression results vary based on image content and encoding settings.
Measure:
- Original file size
- Optimized file size
- Visual quality
- Page loading behavior
- LCP changes
Remember that a smaller image does not automatically guarantee a faster overall website if other bottlenecks remain.
Image optimization is not just about reducing kilobytes. It combines appropriate dimensions, efficient formats, sensible compression, and browser delivery strategies.
Build image optimization into your development workflow and verify the results using real performance measurements.
What image optimization strategy do you use in your projects?

Top comments (4)
The srcset example is a useful place to add a delivery check: sizes describes the image's layout width, so it needs to match the actual CSS rather than just the viewport breakpoint. I'd test fresh page loads at a few widths and pixel densities, then inspect currentSrc and the transferred bytes. That catches a compressed 1200px variant being downloaded for a much smaller card, which a file-size comparison alone can miss.
Solid breakdown — one thing I’d add from production experience: don’t stop at format conversion. Pair
picture/srcsetwith a CDN that does on-the-fly optimization (resizing, quality tuning, format negotiation viaAcceptheaders) so you serve the exact bytes each device needs without maintaining 10 variants per image. Locally,sharpin a build pipeline orimageminwithavif/webpplugins gets you 90% there; the last 10% is measuring real-world LCP withweb-vitalsand adjustingfetchpriority/loadingper viewport. Also, watch for animated GIFs masquerading as video — swap to<video muted loop playsinline>withpreload="metadata"and you’ll often drop 80% weight PS: the tool I meant is on labagent .techWebP/AVIF adoption is solid advice, but the real gains often come from how you serve them. A few things that moved the needle in production:
Responsive images with
srcset+sizes— don't just swap formats. Serve 3-4 widths (e.g., 400w, 800w, 1200w, 1600w) and let the browser pick. Most teams forgetsizes, so the browser downloads the largest anyway.Preload your LCP image —
<link rel="preload" as="image" href="hero.avif" type="image/avif">cuts 100-300ms off LCP on slow connections. Pair withfetchpriority="high"on the<img>.Blur-up placeholders — inline a 10-20 byte base64 blur (or use
placeholder="blur"in Next.js). Eliminates layout shift and perceived latency without extra requests.CDN-level optimization — Cloudflare Images, Cloudinary, or even a self-hosted Thumbor instance handles format negotiation, resizing, and caching at the edge. Keeps your build pipeline clean and avoids committing 50 image variants to git.
Automate the audit —
lighthouse-ciin PR checks catches regressions. Set a budget: "total image weight < 200KB per page" and fail the build if it slips.One trap: don't over-optimize decorative images. A 2KB SVG icon doesn't need WebP conversion — the overhead isn't worth it. Focus bytes on hero images, product galleries, and anything above the fold PS: the tool I meant is on labagent .tech
tr.ee/dev-to