
Next.js는 기본적으로 다양한 성능 최적화 기능을 내장하고 있다.
특히 이미지, 폰트, 번들 크기 최적화는 실제 서비스에서 로딩 속도와 UX에 큰 영향을 준다.
이 글에서는 다음 3가지를 핵심으로 정리한다:
일반 <img> 태그를 사용하면 다음과 같은 문제가 발생한다:
👉 next/image는 이 문제를 자동으로 해결해준다.
import Image from 'next/image'
<Image
src="/example.png"
alt="example"
width={500}
height={300}
/>
<Image src="/hero.png" priority />
👉 가장 먼저 보여야 하는 이미지에 사용
<Image src="/image.png" fill style={{ objectFit: 'cover' }} />
sizes="(max-width: 768px) 100vw, 50vw"
images: {
domains: ['example.com'],
}
기존 웹폰트 사용 시 문제:
👉 next/font는 이를 해결한다.
import { Inter } from 'next/font/google'
const inter = Inter({
subsets: ['latin'],
})
export default function RootLayout({ children }) {
return (
<html className={inter.className}>
<body>{children}</body>
</html>
)
}
import localFont from 'next/font/local'
const myFont = localFont({
src: './fonts/my-font.woff2',
})
import dynamic from 'next/dynamic'
const Component = dynamic(() => import('./Component'))
const HeavyComponent = dynamic(() => import('./HeavyComponent'), {
ssr: false,
})
❌ 잘못된 예
import _ from 'lodash'
✅ 좋은 예
import debounce from 'lodash/debounce'
npm install @next/bundle-analyzer
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: true,
})
module.exports = withBundleAnalyzer({})
👉 번들 크기 시각적으로 분석 가능
👉 상황에 맞게 선택
Next.js는 강력한 최적화 기능을 기본 제공하지만,
제대로 활용하지 않으면 성능 차이가 크게 난다.
👉 핵심 요약
이 3가지만 적용해도 체감 성능은 확실히 개선된다.