KoderSolutionKoderSolution LogoKoderSolution Logo
HomeArticlesTutorialsToolsRun CodeForumAI Lab
▲

Next.js

Topic Hub & Articles

Next.js Intro

10 min

Next.js Installation

10 min

Next.js Routing

10 min

Next.js Pages

10 min

Next.js App Router

10 min

Recap Quiz

Gated

Milestone Assessment

Next.js Layouts

10 min

Next.js Linking and Navigating

10 min

Next.js Loading UI and Streaming

10 min

Next.js Error Handling

10 min

Next.js Data Fetching

10 min

Recap Quiz

Gated

Milestone Assessment

Next.js Server Actions

10 min

Next.js Rendering

10 min

Next.js CSS Modules

10 min

Next.js Image Optimization

10 min

Next.js Font Optimization

10 min

Recap Quiz

Gated

Milestone Assessment

Next.js Script Optimization

10 min

Next.js Static File Serving

10 min

Next.js Metadata

10 min

Next.js API Routes

10 min

Next.js Middleware

10 min

Recap Quiz

Gated

Milestone Assessment

Next.js Authentication

10 min

Next.js Deployment

10 min

Next.js Internationalization

10 min

Next.js Security

10 min

Next.js Performance

10 min

Recap Quiz

Gated

Milestone Assessment

Progress
0%

0 / 25 Lessons

KoderSolutionKoderSolution LogoKoderSolution Logo

The world’s most advanced technical ecosystem for modern software engineers. Learn, build, and grow with next-generation developer tools and resources.

Facebook PageX (Twitter) ProfileYouTube ChannelContact Support

Engineering Newsletter

Subscribe for weekly software engineering tutorials, architecture guides, and developer tool updates.

Platforms

  • Technical Articles
  • Interactive Tutorials
  • AI Coding Lab
  • Developer Forum
  • Developer Tools

Pages

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of Service
  • Refund Policy
  • Disclaimer
  • Advertisement

Popular Topics

  • PHP
  • Laravel
  • Python
  • React.Js
  • MySQL
© 2026 KoderSolutionAll Rights Reserved
Developed Bymaksudur.dev
Next.jsNext.js Tutorial
Lesson

Next.js Static File Serving

10 min reading
Free Course

Next.js Static File Serving: Managing Assets in public/

Next.js static file serving exposes any file placed inside the root public/ directory at your site's base URL /. Use public/ for favicons, downloadable PDFs, robots.txt, brand logos, and verification files.

Files inside public/ are served directly without Webpack or Turbopack bundling. A file at public/logo.svg becomes reachable at https://yoursite.com/logo.svg right away.

Mapping public/ Folders to URLs

Organize static assets cleanly in subfolders under public/, while keeping URL references rooted at /.

my-next-app/
├── app/
│   └── page.tsx
└── public/
    ├── favicon.ico
    ├── robots.txt
    ├── docs/
    │   └── privacy-policy.pdf
    └── images/
        └── brand-mark.svg
  • public/favicon.ico maps to /favicon.ico
  • public/docs/privacy-policy.pdf maps to /docs/privacy-policy.pdf
  • public/images/brand-mark.svg maps to /images/brand-mark.svg

Referencing Static Files in Components

Start asset paths with a leading slash / and leave out the word public from every URL string.

// app/components/SiteHeader.tsx
import Image from 'next/image';

export default function SiteHeader() {
  return (
    <header className="flex items-center justify-between p-4 border-b">
      <Image
        src="/images/brand-mark.svg"
        alt="Workspace Logo"
        width={36}
        height={36}
      />
      <a
        href="/docs/privacy-policy.pdf"
        target="_blank"
        rel="noopener noreferrer"
        className="text-sm text-blue-600 underline"
      >
        Privacy Policy (PDF)
      </a>
    </header>
  );
}

App Router Metadata Files vs. public/

Next.js also supports special files directly inside app/, such as app/icon.png, app/robots.ts, and app/sitemap.ts. Use app/ conventions for dynamic sitemaps or generated icons, and keep fixed files like downloadable PDFs in public/.

Common Mistakes

  • Writing /public/logo.svg in src or href: Next.js strips public from the public URL, so /public/logo.svg returns a 404 error.
  • Creating a page route with the same name as a static file: Having both public/about.html and app/about/page.tsx causes routing conflicts.
  • Putting API keys or private config files in public/: Every file inside public/ can be downloaded openly by anyone on the internet.

Frequently Asked Questions

Are files added to public/ after npm run build served automatically?

No, Next.js indexes public/ at build time; dynamically uploaded user files should live in object storage like S3 or Cloudflare R2.

How does Next.js cache assets inside public/?

By default Next.js avoids aggressive immutable caching on public/ files because their filenames do not contain content hashes, though CDNs can cache them with custom headers.

Should component photos live in public/ or assets/?

Photos used in JSX can live in public/ or be imported directly from a src/assets/ folder so <Image> reads dimensions automatically.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Related Developer Tools & Topic Hub

Next.js Topic Hub
JSON Formatter
Validate and format JSON payloads
HTML Formatter
Format HTML markup
CSS Formatter
Clean and format stylesheets
All Next.js Articles
Deep-dive guides, tips & discussions
PreviousNext.js Script Optimization
Continue JourneyNext: Next.js Metadata

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum