Hey, who turned out the lights? 🔦
Move your mouse to illuminate the page
Web

How to Convert Standard Web Images to Next-Gen Formats for Better Site Performance

How to Convert Standard Web Images to Next-Gen Formats for Better Site Performance

In today’s web performance landscape, image optimization is crucial for achieving high scores in Google PageSpeed Insights, Lighthouse audits, and improving your Core Web Vitals. One of the most impactful optimizations you can make is converting your standard JPEG and PNG images to next-generation formats like WebP and AVIF.

What Are Next-Generation Image Formats?

Next-generation image formats are modern compression standards that deliver significantly smaller file sizes while maintaining visual quality. The most widely supported next-gen formats include:

  • WebP: Developed by Google, offering 25-35% smaller file sizes than JPEG
  • AVIF: The newest format, providing up to 50% better compression than JPEG
  • JPEG XL: An emerging format with excellent compression and quality

Why Converting to Next-Gen Formats Matters for SEO

Search engines, particularly Google, heavily weight page load speed as a ranking factor. Images often account for 60-70% of a webpage’s total size, making them the biggest opportunity for performance improvements.

Core Web Vitals Impact

Converting to next-gen formats directly improves your Core Web Vitals metrics:

  • Largest Contentful Paint (LCP): Faster loading hero images
  • First Input Delay (FID): Reduced resource competition during page load
  • Cumulative Layout Shift (CLS): More predictable image loading behavior

Browser Support and Implementation Strategy

Before diving into conversion methods, it’s important to understand browser support:

  • WebP: Supported by 95%+ of browsers (all modern browsers)
  • AVIF: Supported by 85%+ of browsers (Chrome, Firefox, Safari 16+)
  • JPEG XL: Limited support (primarily Chrome with flags enabled)

The recommended approach is to implement progressive enhancement using the HTML <picture> element or server-side detection.

Method 1: HTML Picture Element Implementation

The most SEO-friendly approach uses the <picture> element to serve next-gen formats with fallbacks:

html

<picture>
  <source srcset="hero-image.avif" type="image/avif">
  <source srcset="hero-image.webp" type="image/webp">
  <img src="hero-image.jpg" alt="Descriptive alt text for SEO" 
       loading="lazy" width="800" height="600">
</picture>

This method ensures:

  • Search engine crawlers can access the fallback image
  • Users get the most optimized format their browser supports
  • Proper SEO attributes (alt text, dimensions) are maintained

Method 2: Server-Side Content Negotiation

For larger sites, implement server-side logic to serve appropriate formats based on the Accept header:

javascript

// Express.js example
app.get('/images/:filename', (req, res) => {
  const acceptHeader = req.headers.accept;
  const filename = req.params.filename;
  
  if (acceptHeader.includes('image/avif')) {
    res.sendFile(`${filename}.avif`);
  } else if (acceptHeader.includes('image/webp')) {
    res.sendFile(`${filename}.webp`);
  } else {
    res.sendFile(`${filename}.jpg`);
  }
});

Image Conversion Tools and Workflows

Online Conversion Tools

For small batches of images:

  • Squoosh – Google’s web-based image optimizer
  • Convertio – Supports multiple next-gen formats
  • CloudConvert – API available for automation

Command Line Tools

For batch processing and automation:

bash

# Install cwebp (WebP encoder)
sudo apt-get install webp

# Convert JPEG to WebP
cwebp -q 80 input.jpg -o output.webp

# Batch convert all JPEGs in a directory
for file in *.jpg; do
  cwebp -q 80 "$file" -o "${file%.jpg}.webp"
done

Build Process Integration

Webpack with next-optimized-images

javascript

// next.config.js
const withOptimizedImages = require('next-optimized-images');

module.exports = withOptimizedImages({
  optimizeImages: true,
  optimizeImagesInDev: false,
  mozjpeg: {
    quality: 80,
  },
  webp: {
    quality: 80,
  },
});

Gulp automation

javascript

const gulp = require('gulp');
const imagemin = require('gulp-imagemin');
const webp = require('gulp-webp');

gulp.task('convert-webp', () => {
  return gulp.src('src/images/**/*.{jpg,jpeg,png}')
    .pipe(webp({ quality: 80 }))
    .pipe(gulp.dest('dist/images/'));
});

Content Delivery Network (CDN) Solutions

Many CDNs now offer automatic next-gen format conversion:

Cloudflare Polish

Enable automatic WebP and AVIF conversion:

  • Navigate to Speed > Optimization in Cloudflare dashboard
  • Enable “WebP” and “AVIF” conversion
  • Images are automatically served in optimal formats

ImageKit Integration

html

<!-- Automatic format optimization -->
<img src="https://ik.imagekit.io/your-id/image.jpg?tr=f-auto,q-80" 
     alt="Auto-optimized image">

Performance Testing and Validation

After implementing next-gen formats, validate your improvements:

Google PageSpeed Insights

Test your pages at PageSpeed Insights to see:

  • “Serve images in next-gen formats” recommendation status
  • Overall performance score improvements
  • Core Web Vitals metrics

Chrome DevTools

  1. Open DevTools → Network tab
  2. Reload page and filter by “Img”
  3. Verify next-gen formats are being served
  4. Check file size reductions

WebPageTest

Use WebPageTest for detailed performance analysis:

  • Waterfall charts showing image load times
  • Visual comparison of load performance
  • Advanced metrics like Speed Index

SEO Best Practices for Next-Gen Images

Maintain Proper Alt Text

html

<picture>
  <source srcset="product-hero.avif" type="image/avif">
  <source srcset="product-hero.webp" type="image/webp">
  <img src="product-hero.jpg" 
       alt="Blue wireless headphones on white background - Model XYZ-123" 
       loading="lazy">
</picture>

Implement Structured Data

json

{
  "@type": "Product",
  "image": [
    "https://example.com/product-image.jpg",
    "https://example.com/product-image-2.jpg"
  ]
}

Use Descriptive Filenames

Instead of: IMG_1234.webp Use: wireless-bluetooth-headphones-blue.webp

Common Implementation Mistakes to Avoid

Missing Fallback Images

Always provide JPEG/PNG fallbacks for maximum compatibility:

html

<!-- ❌ Wrong: No fallback -->
<picture>
  <source srcset="image.webp" type="image/webp">
</picture>

<!-- ✅ Correct: Includes fallback -->
<picture>
  <source srcset="image.webp" type="image/webp">
  <img src="image.jpg" alt="Description">
</picture>

Over-Compression

Don’t sacrifice quality for file size. Test different quality settings:

  • WebP: Quality 75-85 typically optimal
  • AVIF: Quality 50-65 often sufficient
  • Always visually inspect results

Ignoring Image Dimensions

Specify width and height attributes to prevent layout shifts:

html

<img src="image.webp" alt="Description" width="400" height="300">

Measuring Success: Key Performance Indicators

Track these metrics to quantify your optimization success:

Technical Metrics

  • Page Load Time: Target 2-3 second improvement
  • Total Page Size: Expect 30-50% reduction in image bytes
  • Lighthouse Performance Score: Aim for 90+ score
  • Core Web Vitals: Green scores across all metrics

Business Metrics

  • Bounce Rate: Often decreases with faster load times
  • Conversion Rate: Typically improves with better performance
  • Mobile User Experience: Particularly benefits from smaller images

Advanced Optimization Techniques

Responsive Image Delivery

Combine next-gen formats with responsive images:

html

<picture>
  <source media="(min-width: 800px)" 
          srcset="hero-large.avif 1200w, hero-medium.avif 800w" 
          type="image/avif">
  <source media="(min-width: 800px)" 
          srcset="hero-large.webp 1200w, hero-medium.webp 800w" 
          type="image/webp">
  <source media="(min-width: 400px)" 
          srcset="hero-small.avif" 
          type="image/avif">
  <img src="hero-fallback.jpg" alt="Hero image description">
</picture>

Lazy Loading Integration

Combine with native lazy loading for maximum performance:

html

<img src="image.webp" alt="Description" loading="lazy" decoding="async">

Future-Proofing Your Image Strategy

Preparing for JPEG XL

While support is limited, JPEG XL shows promise:

  • Superior compression ratios
  • Lossless transcoding from existing JPEG
  • Built-in progressive loading

Monitoring New Formats

Stay updated on emerging formats through:

  • Can I Use for browser support tracking
  • Web performance communities and blogs
  • Browser vendor announcements

Conclusion

Converting standard web images to next-generation formats is one of the most effective ways to improve your site’s performance scores and SEO rankings. By implementing WebP and AVIF formats with proper fallbacks, you can achieve:

  • 30-50% reduction in image file sizes
  • Significantly improved Core Web Vitals scores
  • Better user experience, especially on mobile devices
  • Higher search engine rankings through improved page speed

The key is to implement progressive enhancement, maintain proper SEO attributes, and continuously monitor your performance improvements. Start with your most important pages and images, then gradually expand your optimization efforts across your entire site.

Remember: faster loading images lead to better user experiences, higher engagement, and improved search rankings. The investment in next-gen image formats will pay dividends in both performance metrics and business outcomes.