next/image 解决了哪些图片性能问题?
next/image 是优化后的 <img> 替代,自动:
- 懒加载(默认
loading="lazy") - 防止布局抖动:要求显式
width/height(或用fill)预留空间 - 自动优化格式/尺寸:服务端按需转 WebP/AVIF、按设备分辨率提供
srcset - 占位:
placeholder="blur"生成模糊预览
import Image from 'next/image'
<Image src="/hero.png" alt="hero" width={1200} height={600} priority /> // priority 跳过懒加载(首屏大图)远程图片需在
next.config的images.remotePatterns里白名单。配 CDN 时图片优化由 Next 的/_next/image代理完成。