C.W.K.
Stream
Lesson 05 of 08 · published

next/font

~18 min · next/font, self-hosted fonts, CLS

Level 0Curious
0 XP0/68 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

해주는 것

next/font 가 build time 에 font download, static asset 와 함께 self-host (Google 한테 request 안 함), CSS size-adjust 사용해서 font swap layout shift 제거. 한 import, network privacy 걱정 0, font loading 의 CLS 0.

Google font

next/font/google 에서 import; family 고르고, subset 골라, optional 로 CSS variable 에서 사용할 variable 명명 (Tailwind 친화).

Local font

woff2 file 을 repo 어디든 drop 하고 next/font/local 에서 import. Proprietary 또는 custom font 위해.

Code

next/font 통한 Google font·tsx
import { Inter, JetBrains_Mono } from 'next/font/google';

const inter = Inter({ subsets: ['latin'], display: 'swap' });
const mono = JetBrains_Mono({ subsets: ['latin'], variable: '--font-mono' });

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en" className={`${inter.className} ${mono.variable}`}>
      <body>{children}</body>
    </html>
  );
}
Local font·tsx
import localFont from 'next/font/local';

const geist = localFont({
  src: [
    { path: './fonts/Geist-Regular.woff2', weight: '400' },
    { path: './fonts/Geist-Bold.woff2',    weight: '700' },
  ],
  variable: '--font-geist',
});

External links

Exercise

Project 에 body text 위한 Google font 한 개와 heading 위한 한 개로 next/font 추가. DevTools Network tab 이 runtime 에 fonts.googleapis.com 에 request 안 보이는지 확인.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.