Next.jsEasy
What is the public folder in Next.js used for?
public/ holds static files served as-is from the site root: public/logo.png is available at /logo.png. Use it for favicons, robots.txt, images referenced by URL, downloadable files and verification files.
Rules
- Files are served from
/, never with/publicin the URL. - Only files present at build time are served. Files added at runtime are not picked up; use object storage (S3, R2, Vercel Blob) for user uploads.
- A file in
public/must not share a name with a page route, or there is a conflict. - Next.js cannot fingerprint these files, so browsers may cache an old version. By default they get
Cache-Control: public, max-age=0, meaning revalidate every time.
When to prefer other options
- Imported images (
import hero from "./hero.jpg") get automatic width, height and blur placeholders withnext/image, and hashed URLs that can be cached forever. - Favicons and OG images can use the metadata file conventions (
app/icon.png,app/opengraph-image.png,app/favicon.ico), which Next.js turns into the right<link>tags. robots.txtandsitemap.xmlcan be generated withapp/robots.tsandapp/sitemap.ts.
Using public images with next/image
Reference them by path and pass explicit width and height, because Next.js cannot read their dimensions automatically.
Code example
tsx
1// public/2// ├── favicon.ico -> /favicon.ico3// ├── images/team.jpg -> /images/team.jpg4// └── docs/guide.pdf -> /docs/guide.pdf56// app/about/page.tsx7import Image from "next/image";8import hero from "./hero.jpg"; // imported: size and blur placeholder known at build910export default function About() {11 return (12 <main>13 <Image src={hero} alt="Our office" placeholder="blur" preload />14 {/* public/ file: give explicit dimensions */}15 <Image src="/images/team.jpg" alt="The team" width={800} height={500} />16 <a href="/docs/guide.pdf" download>17 Download the guide18 </a>19 </main>20 );21}
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.