Skip to the solution
EasyFrontend4 min read

What is the difference between the /public folder and imported assets in Next.js?

734 views

The problem

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.png becomes /logo.png), exactly as they are.
  • Because the URL never changes, they cannot be cached forever: Next.js serves them with max-age=0 so 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.

  • nextjs
  • public
  • assets
  • static-files

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

4 min read Β· 8 sections

Read the code

The same image from public and as an import
import Image from "next/image";
import logo from "./logo.png"; // hashed URL, dimensions and blur placeholder known at build time

export function Header() {
  return (
    <header>
      <Image src={logo} alt="Company" placeholder="blur" />
      {/* public/partner-badge.png: stable URL, dimensions must be given */}
      <Image src="/partner-badge.png" alt="Partner" width={120} height={40} />
    </header>
  );
}

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 11 of 129 in Next.js

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

All Next.js questions
Up nextEasy

How do you run Turbopack locally β€” `next dev --turbo` vs default?

Continue