Public Directory
Use thepublic/ directory to serve static assets at a defined URL without any processing. Files in this directory are served as-is at the server root.
Accessing Public Assets
You can reference files in thepublic/ directory from your application’s code or browser using the root URL /.
public/img/nuxt.png is available at the static URL /img/nuxt.png.
When to Use Public
Choose thepublic/ directory when you:
- Need files accessible at a static, predictable URL
- Want to serve assets without build-time processing
- Have files that don’t require optimization or transformation
Assets Directory
Nuxt uses Vite (default) or webpack to build and bundle your application. Theapp/assets/ directory stores files that you want these build tools to process.
How Build Tools Process Assets
Build tools can transform your assets for:- Performance optimization (minification, compression)
- Browser cache invalidation (file hashing)
- Modern format conversion
- Code splitting and lazy loading
Referencing Assets
By convention, place files you want processed in theapp/assets/ directory. Reference these files in your code using the ~/assets/ path.
The
app/assets/ directory has no auto-scan functionality. You can use any other directory name if you prefer.Choosing the Right Directory
Use this guide to decide where to place your assets:Best Practices
- Keep public/ lean: Only place files that truly need static URLs
- Leverage assets/ for optimization: Let build tools optimize images, styles, and other processable assets
- Use descriptive paths: Organize files in subdirectories (
public/img/,assets/styles/) - Consider CDN deployment: For production, both directories can be deployed to a CDN for better performance