Course contentsShow
← Web Development
Lesson 1379 of 2,98225. Build Tools and BundlersFree lesson

Public Directory and Static Assets

Understanding the public folder for assets that should not be processed by Vite.

Public Directory and Static Assets

What you'll learn: How to use Vite's public folder for assets that bypass the build process and remain unchanged in your final application.

What Is the Public Directory?

In Vite, the public folder is a special directory for assets that should be served as-is, without any processing, transformation, or optimization by the bundler. When you build your project, files from public are copied directly to the root of your output directory without going through Vite's asset pipeline.

Think of it like a "no-touch zone" at the airport: while your regular luggage (imported assets) gets scanned, tagged, and processed, items in the public folder walk straight through without inspection.

When to Use the Public Folder

Use public for:

  • Fixed-path assets like robots.txt or favicon.ico that must live at specific URLs
  • Assets referenced by HTML directly, not through JavaScript imports
  • Third-party files you don't want hashed or transformed
  • Large files that rarely change and don't need cache-busting filenames

For example, if you need mysite.com/logo.png to always exist at that exact path, place logo.png in the public folder.

How It Works

Files in public are referenced using absolute paths from the root. If you have public/images/banner.jpg, reference it as /images/banner.jpg in your HTML or CSS—never use import statements for public assets.

During development, Vite serves these files directly. During build, they're copied to your dist folder at the same paths.

Key Takeaway: Use Vite's public folder for assets that need fixed URLs and shouldn't be processed—they'll be copied directly to your build output without transformation or hash-based naming.