Static Files
Serve static files with caching, ETags, and optimized headers for efficient asset delivery.
Basic Static File Serving
MoroJS provides built-in static file serving middleware with support for caching, ETags, and optimized headers.
Basic Static File Serving
typescript
Static File Features
- • Automatic file serving from directory
- • ETag support for cache validation
- • Last-Modified headers
- • Custom cache headers
- • Directory index support
- • Multiple static directories
Advanced Configuration
Advanced Static File Configuration
typescript
Best Practices
Do
- • Use long cache times for static assets
- • Enable ETags for cache validation
- • Use CDN for production deployments
- • Set appropriate cache headers
- • Use versioned filenames for cache busting
- • Organize files by type
Don't
- • Serve sensitive files as static
- • Use short cache times for assets
- • Disable ETags unnecessarily
- • Serve large files directly
- • Allow directory listing
- • Skip cache headers