Skip to content

Docs: Image Optimization Deep Dive #78857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

delbaoliveira
Copy link
Contributor

Deep dive on how image optimization works in Next.js

Closes: https://linear.app/vercel/issue/DOC-4634/new-page-how-image-optimization-works-in-nextjs

@ijjk ijjk added created-by: Next.js DevEx team PRs by the DX team. Documentation Related to Next.js' official documentation. labels May 6, 2025
Copy link
Contributor

github-actions bot commented May 6, 2025

Hi there 👋

It looks like this PR introduces broken links to the docs, please take a moment to fix them before merging:

Broken link Type File
/docs/app/api-reference/components/image#width-and-height hash /docs/01-app/04-deep-dive/image-optimization.mdx
/docs/app/api-reference/components/image#width-and-height hash /docs/01-app/04-deep-dive/image-optimization.mdx
/docs/app/api-reference/components/image#minimum-cache-ttl hash /docs/01-app/04-deep-dive/image-optimization.mdx

Thank you 🙏


### Duration

TODO: What is the default duration with no configuration?
Copy link
Contributor Author

@delbaoliveira delbaoliveira May 6, 2025

Choose a reason for hiding this comment

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

What is the default cache duration if not configured?

Copy link
Member

@styfle styfle May 12, 2025

Choose a reason for hiding this comment

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

60 seconds. See images.minimumCacheTTL config

Comment on lines +61 to +62
- [Caches](#caching-and-revalidating-images) the optimized image.
- Serves the optimized images at runtime.
Copy link
Contributor Author

@delbaoliveira delbaoliveira May 6, 2025

Choose a reason for hiding this comment

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

Where are the images cached and served from?

On vercel vs. self-hosting

Copy link
Member

Choose a reason for hiding this comment

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

Basically the same as ISR cache. Do we have a docs on that we can reuse?

Comment on lines +40 to +48
### Supported image formats

The built-in loader supports common web-friendly formats:

- `jpeg`
- `png`
- `webp`
- `avif`
- `tiff`
Copy link
Contributor Author

@delbaoliveira delbaoliveira May 6, 2025

Choose a reason for hiding this comment

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

Confirm supported vs. unsupported image formats

Copy link
Member

Choose a reason for hiding this comment

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

We need to differentiate input vs output types

Copy link
Member

Choose a reason for hiding this comment

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

The images.formats config is how you configure the output type

Comment on lines +59 to +62
- Generates multiple [image sizes](#image-sizing) for different screens using modern [image formats](#supported-image-formats).
- Builds the URLs pointing to the optimized image version, and creates a `srcset` attribute.
- [Caches](#caching-and-revalidating-images) the optimized image.
- Serves the optimized images at runtime.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally, these steps should be sequential

delbaoliveira added a commit that referenced this pull request May 8, 2025
Closes:
- https://linear.app/vercel/issue/DOC-4626/images
- https://linear.app/vercel/issue/DOC-4610/split-image-and-font-pages

Redirects: #78769

**Housekeeping:** 
- Deletes BYA images page
- Creates relevant getting started docs in `/pages`
- Splits "Images and Fonts" into "Images" and "Fonts" pages to allow us
to add more context to each page in the future

**API reference**: 
- Improves image API reference to follow more of a consistent format and
language
- Adds examples

**Follow-up:** #78857
- Create a Deep Dive Guide on how image optimization works

---------

Co-authored-by: Rich Haines <hello@richardhaines.dev>
### Unsupported image formats

- **Animated images** (e.g., GIF, APNG, ets) as served as-is, bypassing optimization.
- **SVGs** are blocked by default unless [`unoptimized`](/docs/app/api-reference/components/image#unoptimized) or [`dangerouslyAllowSVG`](/docs/app/api-reference/components/image#dangerouslyallowsvg) is enabled.
Copy link
Member

Choose a reason for hiding this comment

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

We should also mention that they are bypassed when dangerouslyAllowSVG is true


### Image Sizing

One of the most common image-related performance issues is [layout shift](https://web.dev/articles/cls). This happens when an image pushes other elements around the page as it loads in. It’s a UX problem that it has its own Core Web Vital: [Cumulative Layout Shift](https://web.dev/cls/). Layout shift can be prevented by defining the image dimensions. This allows the browser to reserve enough space for the image before it loads.
Copy link
Member

Choose a reason for hiding this comment

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

Probably worth mentioning https://web.dev/articles/lcp too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
created-by: Next.js DevEx team PRs by the DX team. Documentation Related to Next.js' official documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants