KoderSolution Logo
HomeArticlesTutorialsForumAI LabRun Code
KoderSolution Logo

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

Engineering Newsletter

Join 100,000+ engineers receiving curated high-signal content weekly.

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.js

Topic Hub & Articles

Next.js Intro

10 min

Recap Quiz

5 Questions

Next.js Installation

10 min

Next.js Routing

10 min

Next.js Pages

10 min

Recap Quiz

5 Questions

Next.js App Router

10 min

Next.js Layouts

10 min

Next.js Linking and Navigating

10 min

Recap Quiz

5 Questions

Next.js Loading UI and Streaming

10 min

Next.js Error Handling

10 min

Next.js Data Fetching

10 min

Recap Quiz

5 Questions

Next.js Server Actions

10 min

Next.js Rendering

10 min

Next.js CSS Modules

10 min

Recap Quiz

5 Questions

Next.js Image Optimization

10 min

Next.js Font Optimization

10 min

Next.js Script Optimization

10 min

Recap Quiz

5 Questions

Next.js Static File Serving

10 min

Next.js Metadata

10 min

Next.js API Routes

10 min

Recap Quiz

5 Questions

Next.js Middleware

10 min

Next.js Authentication

10 min

Next.js Deployment

10 min

Recap Quiz

5 Questions

Next.js Internationalization

10 min

Next.js Security

10 min

Next.js Performance

10 min

Progress
0%

0 / 25 Lessons

Next.jsNext.js Tutorial
Lesson

Next.js Static File Serving

10 min reading
Free Course

Next.js Static File Serving: Managing Assets in the Public Directory

Next.js Static File Serving demonstrates how to organize static assets like images, brand logos, favicons, site manifests, and robots files using the root /public directory.

Files located inside the public/ directory are mapped directly to the root URL / path of your web application.

Public File Directory Mapping

Consider the following folder contents in your project:

my-project/
├── public/
│   ├── favicon.ico
│   ├── logo.svg
│   ├── docs/
│   │   └── terms.pdf
│   └── images/
│       └── hero-banner.png

These assets are accessible directly in the browser at the following URL paths:

  • public/logo.svg -> https://example.com/logo.svg
  • public/docs/terms.pdf -> https://example.com/docs/terms.pdf
  • public/images/hero-banner.png -> https://example.com/images/hero-banner.png

Referencing Public Assets in Code

Reference files stored inside public/ using absolute root path strings:

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

export default function BrandHeader() {
  return (
    <header className="flex items-center space-x-4 p-4 border-b">
      {/* Root reference directly points to public/logo.svg */}
      <Image
        src="/logo.svg"
        alt="Company Brand Logo"
        width={40}
        height={40}
      />
      <a href="/docs/terms.pdf" target="_blank" className="text-blue-600 underline">
        Download Terms (PDF)
      </a>
    </header>
  );
}

Caching for Static Files

Assets served from the public/ folder are immutable by default and cached aggressively by browsers and CDN edge nodes.

Best Practices

  • Do Not Name Files public inside Code Imports: Use /logo.svg instead of /public/logo.svg.
  • Keep Sensitive Data Out of Public: Never store private API keys, credentials, or customer database backups inside the public/ folder.

Summary

The public/ directory simplifies serving static assets. Root URL mapping allows clean referencing of brand logos, downloadable documents, and site icons.

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

Recommended Courses & Books

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum