Skip to content

Conversation

@KaziMahbuburRahman
Copy link

Title

docs: add example for enabling both AVIF and WebP image formats

Description

What?

This PR enhances the image component documentation by adding examples showing how to enable both AVIF and WebP image formats together in next.config.js. It also updates the image-component example to demonstrate this configuration.

Why?

Currently, the documentation only shows examples for:

  • WebP only (default): formats: ['image/webp']
  • AVIF only: formats: ['image/avif']

However, many developers want to enable both formats together to:

  • Prefer AVIF for browsers that support it (better compression, ~20% smaller files)
  • Fall back to WebP for broader browser compatibility
  • Maximize image optimization across different browsers

This configuration is a best practice but wasn't clearly documented with an example.

How?

  • Added example configuration formats: ['image/avif', 'image/webp'] to App Router image component documentation
  • Added the same example to Pages Router (legacy) image component documentation for consistency
  • Updated examples/image-component/next.config.js to demonstrate the configuration
  • Added clarification that the order matters - Next.js uses the first format in the array that the browser supports

Changes Made

  • docs/01-app/03-api-reference/02-components/image.mdx - Added AVIF + WebP example
  • docs/02-pages/04-api-reference/01-components/image-legacy.mdx - Added AVIF + WebP example
  • examples/image-component/next.config.js - Added formats configuration

Testing

  • Documentation changes only - no code changes
  • Verified examples are syntactically correct
  • Checked that formatting follows Next.js documentation guidelines

Checklist

  • Run pnpm prettier-fix to fix formatting issues (if applicable)
  • Documentation follows the docs guidelines
  • Changes are clear and helpful for developers

… WebP formats. Added configuration examples and clarified caching behavior for multiple formats.
@ijjk ijjk added Documentation Related to Next.js' official documentation. examples Issue was opened via the examples template. labels Nov 16, 2025
@ijjk
Copy link
Member

ijjk commented Nov 16, 2025

Allow CI Workflow Run

  • approve CI run for commit: 87b515d

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

```js filename="next.config.js"
module.exports = {
images: {
formats: ['image/avif', 'image/webp'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this introduce more cache overhead though? I don't mean as in, don't do it cuz of the overhead, but as in, we should probably mention this somewhere

>
> - We still recommend using WebP for most use cases.
> - AVIF generally takes 50% longer to encode but it compresses 20% smaller compared to WebP. This means that the first time an image is requested, it will typically be slower, but subsequent requests that are cached will be faster.
> - When using multiple formats, the order matters. Next.js will use the first format in the array that the browser supports.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this necessary? we do mention this in 755.

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

Labels

Documentation Related to Next.js' official documentation. examples Issue was opened via the examples template.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants