Nextjs-Optimizing(4) - Static Assets(๋ฒ์ญ)
๐์์ํ๋ฉฐ
15.2.2 ๊ณต์๋ฌธ์ ๊ธฐ๋ฐ์ผ๋ก ์์ฑ
๊ณ์ํด์ Static Assets์ ๊ดํ ๋ด์ฉ์ ์์๋ณด์.
1๏ธโฃ Static Assets in public
Next.js๋ ์ด๋ฏธ์ง ๊ฐ์ static ํ์ผ์ root์ public์ด๋ผ๋ ํด๋ ์๋์ ์ ๊ณตํ ์ ์๋ค. ๊ทธ๋ฌ๋ฉด, ๋ค๋ฅธ ์ปดํฌ๋ํธ์์ ๊ธฐ๋ณธ URL(/)๋ก public ๋ด๋ถ์ ํ์ผ์ ์ฐธ์กฐํ ์ ์๊ฒ ๋๋ค.
์๋ฅผ ๋ค์ด public/avatars/me.png
ํ์ผ์ /avatars/me.png
๊ฒฝ๋ก๋ก ์์ฑํ ์ ์๋ค.
1
2
3
4
5
6
7
8
9
import Image from "next/image"
export function Avatar({ id, alt }) {
return <Image src={`/avatars/${id}.png`} alt={alt} width="64" height="64" />
}
export function AvatarOfMe() {
return <Avatar id="me" alt="A portrait of me" />
}
๐งกCaching
Next.js๋ ๋ณ๊ฒฝ๋ ์ ์๊ธฐ์ public ํด๋์ assets์ ์์ ํ๊ฒ ์บ์ํ ์ ์๋ค. ์ ์ฉ๋๋ ๊ธฐ๋ณธ ์บ์ฑ ํค๋๋ ์๋์ ๊ฐ๋ค.
1
Cache-Control: public, max-age=0
๐Robots, Favicons, and others
robots.txt
, favicon.ico
๋ฑ๊ณผ ๊ฐ์ static metadata ํ์ผ์ ๊ฒฝ์ฐ app ํด๋ ๋ด๋ถ์ ํน์ ๋ฉํ๋ฐ์ดํฐ ํ์ผ์ ์ฌ์ฉํด์ผ ํ๋ค.
โจGood to know
- ๋๋ ํฐ๋ฆฌ์ ์ด๋ฆ์
public
์ด์ด์ผ ํ๋ค. ์ด ์ด๋ฆ์ ๋ณ๊ฒฝํ ์ ์์ผ๋ฉฐ, static assets์ ์ ๊ณตํ๋๋ฐ ์ฌ์ฉ๋๋ ์ ์ผํ ๋๋ ํ ๋ฆฌ๋ค.- ๋น๋ ์์ ์
public
๋๋ ํ ๋ฆฌ์ ์๋ ์์ ๋ง Next.js์์ ์ ๊ณต๋๋ค. ์์ฒญ ์์ ์ ์ถ๊ฐ๋ ํ์ผ์ ์ฌ์ฉํ ์ ์๋ค. ๋ฐ๋ผ์ ์๊ตฌ์ ์ ํ์ผ ์ ์ฅ์์๋ Vercel Blob๊ณผ ๊ฐ์ ํ์ฌ ์๋น์ค๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข๋ค.
๐๏ธ์ฐธ๊ณ ์ฌ์ดํธ
This post is licensed under CC BY 4.0 by the author.