-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
base: canary
Are you sure you want to change the base?
Conversation
Hi there 👋 It looks like this PR introduces broken links to the docs, please take a moment to fix them before merging:
Thank you 🙏 |
|
||
### Duration | ||
|
||
TODO: What is the default duration with no configuration? |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
- [Caches](#caching-and-revalidating-images) the optimized image. | ||
- Serves the optimized images at runtime. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
### Supported image formats | ||
|
||
The built-in loader supports common web-friendly formats: | ||
|
||
- `jpeg` | ||
- `png` | ||
- `webp` | ||
- `avif` | ||
- `tiff` |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
- 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. |
There was a problem hiding this comment.
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
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
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