Question presented to candidate: "Where should images, fonts and other static files live in a Next.js app: the public folder, or imported from code? What difference does it make?"
What a strong answer should cover:
- Files in
public/are served from the site root at a fixed URL (public/logo.pngbecomes/logo.png), exactly as they are. - Because the URL never changes, they cannot be cached forever: Next.js serves them with
max-age=0so updates are picked up. - Imported assets (
import logo from "./logo.png") are copied to/_next/static/media/with a content hash and served with a one-year immutable cache. - Imported images also give next/image their width, height and a blur placeholder automatically.
- Use public/ for files that need a stable URL: robots.txt, favicons, verification files, assets referenced by third parties.
Clarifying questions expected:
- "Does anything outside the app need a stable URL for this file?" β then public/.
- "Is it an image used in components?" β import it for hashing and dimensions.
Code / implementation expected: Yes β the same image both ways.