Public assets and local fonts
Scope: Next.js 16.x candidate, App Router, Cache Components disabled, TypeScript. Source walkthroughs and expected outcomes; no framework build or browser execution has been verified.
What you will learn
- Choose a file location
- Explain local font build requirements
Public image URL — partial JSX
<img src="/covers/moss.png" width={240} height={360} alt="" />The decorative cover is requested from the same origin. The bundled original image is 480 × 720, with the same aspect ratio.
How it works
For a root-hosted app, public/covers/moss.png corresponds to /covers/moss.png. Never place private documents there. A local font loader receives a path relative to the file containing the call; it is not an HTTP URL. The returned className applies the configured font, and variable can expose a CSS custom property. Font files require appropriate redistribution rights. This batch uses system fonts in its executable-intent fixture; the optional font example intentionally needs a learner-provided licensed WOFF2 file.
app/layout.tsx — optional font variant, not included in core fixture
import localFont from 'next/font/local';import type { ReactNode } from 'react';const reading = localFont({ src: './fonts/reading.woff2', display: 'swap' });export default function Layout({ children }: { children: ReactNode }) { return <html lang="en"><body className={reading.className}>{children}</body></html>;}If a compatible licensed file exists at app/fonts/reading.woff2, the build prepares the font and the body uses its generated class. Without it this variant will not build.
Common mistake
A path like /public/covers/moss.png incorrectly repeats the directory name for a root-hosted app. Also, a local font path pointing to a missing file cannot be fixed by changing the CSS fallback alone.
Try it yourself
Map public/icons/book.svg to its URL and explain why a staff-only file must stay outside public. For the optional font, document the license and file path before building.
Further reading
Next lesson: Responsive and accessible styling.