Building Progressive Web Apps: Complete Guide
Learn to build Progressive Web Apps (PWAs) with offline capabilities, push notifications, and app-like experiences. Step-by-step guide with service workers, manifest files, and best practices.
Images account for more bytes on average than any other content type on the web, often comprising 50-80% of a webpage's total size. Image optimization is one of the most effective ways to improve your site's performance and Core Web Vitals scores. Properly optimized images load faster, consume less bandwidth, and provide a better user experience across all devices.
Selecting the appropriate image format is crucial for optimal performance. Modern formats offer significantly better compression than traditional formats.
Use the <picture> element to serve modern formats with fallbacks:
<picture>
<source srcset="image.avif" type="image/avif">
<source srcset="image.webp" type="image/webp">
<img src="image.jpg" alt="Description">
</picture>
Never serve an image that is larger than its maximum display size. A 3000x2000px image displayed at 300x200px wastes bandwidth and processing power. Always resize images to match their largest display dimensions across all breakpoints.
Compression reduces file size by removing unnecessary data. Choose between lossy and lossless compression based on your needs.
Reduces file size by 60-80% with minimal visible quality loss. Best for photographs and complex images.
Removes metadata and optimizes encoding without quality loss. Reduces file size by 10-30%.
Lazy loading defers loading of offscreen images until users scroll near them, reducing initial page load time by 30-50%.
<img src="image.jpg" loading="lazy" alt="Description">
The native loading="lazy" attribute is now supported by 95% of browsers. For critical above-the-fold images, use loading="eager" or omit the attribute.
Serve appropriately sized images for different device widths using the srcset attribute.
<img
srcset="small.jpg 320w, medium.jpg 768w, large.jpg 1200w"
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
src="medium.jpg"
alt="Responsive image">
Always specify width and height attributes to prevent layout shifts and improve CLS scores.
<img src="image.jpg" width="800" height="600" alt="Description">
Modern browsers use aspect ratio calculation, so the image will still scale responsively with CSS.
Aim for under 100KB per image for optimal performance. Hero images can be up to 200KB, but most images should be 50-100KB after optimization.
Use both with fallback to JPEG. Serve AVIF to supported browsers (50% smaller), WebP as fallback (25% smaller), and JPEG for maximum compatibility.
Optimized images improve page speed, which is a Google ranking factor. They also improve Core Web Vitals scores (especially LCP) and reduce bounce rates.
Image optimization is essential for modern web performance. By implementing these best practices—choosing the right formats, compressing effectively, using lazy loading, and serving responsive images—you can reduce your page size by 50-80% and dramatically improve load times. Start optimizing your images today and use Ubmetrics to measure the performance improvements.