Skip to content

Conversation

@KaziMahbuburRahman
Copy link
Contributor

Summary

Changes the default image format configuration from WebP-only to AVIF + WebP, enabling better image compression by default while maintaining broad browser compatibility.

What?

  • Updated imageConfigDefault.formats from ['image/webp'] to ['image/avif', 'image/webp']
  • Updated fallback default in image-optimizer.ts to match
  • AVIF will be preferred for browsers that support it, with WebP as automatic fallback

Why?

  1. Better Compression: AVIF provides ~20% better compression than WebP, resulting in smaller file sizes and faster page loads
  2. Modern Browser Support: AVIF is now supported in all major modern browsers (Chrome 85+, Firefox 93+, Safari 16+, Edge 121+)
  3. Automatic Fallback: Browsers that don't support AVIF will automatically receive WebP, ensuring no compatibility issues
  4. Performance: While AVIF encoding is ~50% slower on first request, cached images benefit from smaller file sizes on subsequent requests
  5. Best Practice: This aligns with modern web optimization best practices

Browser Support

  • ✅ Chrome 85+ (September 2020)
  • ✅ Firefox 93+ (October 2021)
  • ✅ Safari 16+ (September 2022)
  • ✅ Edge 121+ (January 2024)

According to caniuse.com, AVIF has ~95% global browser support as of 2024.

How?

  • Changed default in packages/next/src/shared/lib/image-config.ts
  • Updated fallback in packages/next/src/server/image-optimizer.ts for consistency
  • The order matters: AVIF is checked first, then WebP, then original format

Impact

  • Breaking Change: No - existing projects will continue to work, but new projects will get better optimization by default
  • Performance: Slightly slower first-time image encoding (~50% longer), but smaller cached files (~20% reduction)
  • Compatibility: No issues - browsers without AVIF support automatically fall back to WebP

Testing

  • No linting errors
  • Changes are consistent across both files
  • Follows existing code patterns

- Update default formats from ['image/webp'] to ['image/avif', 'image/webp']
- AVIF will be preferred for browsers that support it, with WebP as fallback
- Provides better compression (~20% smaller) while maintaining broad compatibility
- Updated both imageConfigDefault and image-optimizer fallback to be consistent
@ijjk
Copy link
Member

ijjk commented Nov 16, 2025

Allow CI Workflow Run

  • approve CI run for commit: cff76dc

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@philwolstenholme
Copy link
Contributor

@KaziMahbuburRahman I think you might have a linter or something installed locally that has rearranged the imports in image-optimizer.ts unnecessarily?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants