Introduction
ShopNest marketing pages need fast-loading CSS, JS, images, and fonts. Static files live in wwwroot and are served by middleware — with bundling, minification, and CDN fallback for production.
After this article you will
- Configure UseStaticFiles and wwwroot
- Use LibMan for client libraries
- Bundle/minify for production
- Cache bust with asp-append-version
Prerequisites
- Article 11 — Tag Helpers
- ShopNest.Web project from prior lessons
Concept deep-dive
app.UseStaticFiles(); // wwwroot by default
app.UseStaticFiles(new StaticFileOptions {
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "Assets")),
RequestPath = "/assets"
});
LibMan (libman.json) pulls Bootstrap/jQuery without npm. For bundling in .NET 8+, use build-time tools or asp-src-include with minified bundles in wwwroot/dist.
Hands-on — ShopNest Marketing Landing Page
- Create landing page with hero image in wwwroot/images.
- Add LibMan bootstrap + custom site.css.
- Production: minified site.min.css with asp-append-version="true".
Common errors & best practices
- 404 on static file — file not under wwwroot or wrong path.
- Missing MIME type — rare; UseStaticFiles handles common types.
Interview questions
Q: Where do static files go?
A: wwwroot by default; served only if UseStaticFiles runs before routing/endpoints.
Summary
- wwwroot + UseStaticFiles serves CSS/JS/images
- LibMan manages client libs
- Cache busting prevents stale assets after deploy
Previous: Tag Helpers
Next: Entity Framework Core — Introduction
FAQ
Can static files bypass authentication?
Yes — they are public unless you use custom middleware or separate auth rules.