Performance: Public directory for static files
This affects page load speed by serving static assets directly without server processing, improving initial content display.
export default function Header() { return <img src="/logo.png" alt="Logo" />; }
import logo from '../assets/logo.png'; export default function Header() { return <img src={logo} alt="Logo" />; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Importing static files in JS bundle | Minimal | 0 | High due to delayed image load | [X] Bad |
| Serving static files from public directory | Minimal | 0 | Low, images load early | [OK] Good |
public directory in a Next.js project?public folder is designed to hold static files such as images, icons, and documents.public are accessible directly via URL paths starting with /.logo.png stored inside the public folder in a Next.js component?public folder are referenced by their path starting with /, without including the folder name.logo.png in public, use /logo.png as the src value.export default function Logo() {
return <img src="/images/avatar.png" alt="User Avatar" />
}avatar.png is located inside public/images folder.public are served from the root URL path, so /images/avatar.png maps to public/images/avatar.png.http://localhost:3000, so the full URL is http://localhost:3000/images/avatar.png.favicon.ico inside the public folder but your browser shows a 404 error when accessing /favicon.ico. What is the most likely cause?public, accessing /favicon.ico should work unless the file name or extension is incorrect.favicon.ico.png or fav-icon.ico.guide.pdf stored in public/docs so users can download it by clicking a link. Which is the correct way to create the link in a Next.js component?public are accessed by URL paths starting with / and omit the public folder name.<a> tag with href="/docs/guide.pdf" and the download attribute.Pass the test and this pattern moves unknown