์ด๋ฏธ์ง placeholder๋ก ์ฌ์ฉํ๊ธฐ ์ํด https://placehold.co/์์ ๊ฐ์ ธ์ค๋ ค๊ณ ํ์ผ๋, ์์ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
next ๋ฌธ์๋ฅผ ์ฐพ์๋ณด๋ ํด๊ฒฐ๋ฐฉ์์ dangerouslyallowsvg์ค์ ์ ํด์ฃผ๋ฉด ๋๋ค.
ํ์ง๋ง ๋ํดํธ ๋ก๋๊ฐ SVG ์ด๋ฏธ์ง๋ฅผ ์ต์ ํํ์ง ์๋๋ค๋ ๋ฌธ๊ตฌ์ ํจ๊ป, ๊ทธ ์ด์ ๋ฅผ ์ค๋ช ํ๋๋ฐ,
์ฒซ์งธ๋ SVG๋ vector ํฌ๋ฉง์ผ๋ก ์ด๋ฃจ์ด์ก๊ธฐ ๋๋ฌธ์ resize ํ์์ฑ์ด ์๊ณ ,
๋ ๋ฒ์งธ๋ก๋ HTML/CSS ์ ๊ฐ์ ํน์ฑ ๋๋ฌธ์ ์ ์ ํ CSP ํค๋ ์์ด๋ ์ทจ์ฝ์ฑ์ผ๋ก ์ด์ด์ง ์ ์๋ค๋ ๊ฒ์ด๋ค.
๋ฐ๋ผ์ src prop์ด SVG์ธ ๊ฒ์ ์๋ฉด ์ต์ ํํ์ง ์์ ๋ฐฉ์์ผ๋ก ์ฌ์ฉํ๋ ๊ฒ์ด ๋ฐ๋์งํ๋ค๊ณ ํ๋ค.
๊ทธ๋ฆฌ๊ณ contentSecurityPolicy์ contentDispositionType์ ๋น๋กฏํ ์ถ๊ฐ์ ์ธ ์ค์ ๋ ํด์ค์ผ ํ๋ค.
(์๋ฌธ)
The default loader does not optimize SVG images for a few reasons.
First, SVG is a vector format meaning it can be resized losslessly.
Second, SVG has many of the same features as HTML/CSS, which can lead to vulnerabilities without proper Content Security Policy (CSP) headers.
Therefore, we recommended using the unoptimized prop when the src prop is known to be SVG. This happens automatically when src ends with ".svg".
However, if you need to serve SVG images with the default Image Optimization API, you can set dangerouslyAllowSVG inside your next.config.js:
module.exports = { images: { dangerouslyAllowSVG: true, contentDispositionType: 'attachment', contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;", }, }โ
In addition, it is strongly recommended to also set contentDispositionType to force the browser to download the image, as well as contentSecurityPolicy to prevent scripts embedded in the image from executing.
๋ญ๊ฐ ๋ค๋ฅธ ์ด๋ฏธ์ง๋ค์ ๊ตณ์ด dangerousltAllowSVG ์ค์ ์ ํฌ ํ์๊ฐ ์๋๋ฐ ๋ชจ๋ ์ ์ฉํด์ผ ํ๋ค๋ ๊ฒ ๋ถ์ ์ ํด ๋ณด์๋ค.
๐ค ๋ค๋ฅธ ๋ฐฉ๋ฒ์ ์์๊น?
์ฌ์ฉํ๊ณ ์ ํ๋ https://placehold.co/ ์ ๋ค์ด๊ฐ ๋ณด๋ ํ์ฅ์๋ฅผ ๋ณ๊ฒฝํด ์ค ์ ์๋ ์ค์ ์ด ์๋ค.
https://placehold.co/600x400/png ์ด๋ฐ ์์ผ๋ก ๋ณ๊ฒฝ์ ํด์ฃผ๊ณ , ์์์ dangerousltAllowSVG ์ค์ ์ ์ ๊ฑฐํด ์คฌ๋๋ ์๋ฌ๊ฐ ์ ๊ฑฐ๋์๋ค.
https://placehold.co/600x400?text=random/png๋ก๋ ๋ ๋ค์ ์๋ฌ๊ฐ ๋ฐ์ํด์ ์ด์ฉ ์ ์์ด ์ฒซ๋ฒ์งธ ๋ฐฉ๋ฒ์ผ๋ก ๋ค์ ์ค์ ํด์คฌ๋ค.
๐ References
Placehold | A simple, fast and free image placeholder service
placehold.co
https://nextjs.org/docs/app/api-reference/components/image#dangerouslyallowsvg
Components: <Image> | Next.js
Optimize Images in your Next.js Application using the built-in `next/image` Component.
nextjs.org