How Production Mode Works
In production, Mizu serves static files directly from the filesystem or embedded FS:- Browser requests a path
- Mizu checks if itβs an API route
- If no, check if a static file exists at that path
- If file exists β serve it with appropriate cache headers
- If not β serve
index.htmlfor SPA routing
Enabling Production Mode
Automatic Detection
Use auto-detection based on environment:Explicit Production Mode
Force production mode:Building Your Frontend
Before deploying, build your frontend:Vite (React/Vue/Svelte)
dist/:
- Minified JavaScript
- Minified CSS
- Optimized images
- Asset fingerprinting (e.g.,
main.abc123.js)
Angular
dist/my-app/browser/.
Next.js / Nuxt
Build Output Structure
A typical Vite build creates:- Hashed files (
main.abc123.js) can be cached forever - index.html should never be cached (cache: no-cache)
- Manifest maps source files to output files
SPA Fallback Routing
For Single Page Applications, all routes should serveindex.html to let the frontend router handle navigation.
/βdist/index.html/aboutβdist/index.html(file doesnβt exist)/users/123βdist/index.html(file doesnβt exist)/assets/main.jsβdist/assets/main.js(file exists)/api/usersβ Go handler (ignored path)
Caching Strategy
Mizu applies intelligent caching based on file type and fingerprinting.Default Cache Durations
How Hashing Works
Hashed filename (content hash in name):- Old version stays cached (doesnβt break users on old version)
- New version has new filename (forces fresh download)
- Can cache aggressively with
immutabledirective
Custom Cache Configuration
Override default cache durations:Custom Pattern-Based Caching
Cache specific file types differently:- Check custom patterns first
- If no match, check if filename has hash
- If hashed β use
HashedAssetsduration - If unhashed β use
UnhashedAssetsduration - If HTML β use
HTMLduration (or no-cache)
Security Headers
Mizu automatically adds security headers in production:- MIME sniffing attacks (
nosniff) - Clickjacking (
SAMEORIGIN) - XSS attacks (legacy protection)
- Referrer leaking (privacy)
Disable Security Headers
If youβre using the helmet middleware:Source Maps
Source maps help debug production errors by mapping minified code back to source code.Default Behavior
Source maps (.js.map, .css.map) are blocked in production for security:
- Exposes source code structure
- Larger file sizes
- Not needed by end users
Enable Source Maps
For internal or staging environments:Conditional Source Maps
Enable only for specific environments:Embedded Filesystems
For single-binary deployment, embed your frontend into the Go binary:- Single binary contains both backend and frontend
- No need to deploy
dist/folder separately - Simpler deployment
- Faster startup (no disk reads)
- Larger binary size
- Canβt update frontend without rebuilding
- Need to rebuild for frontend changes
URL Prefix
Serve frontend from a subdirectory:/β Go handler (not fronted)/appβdist/index.html/app/aboutβdist/index.html(SPA fallback)/app/assets/main.jsβdist/assets/main.js
Custom Index File
Use a different entry point:Error Handling
Custom Not Found Handler
Run custom logic before SPA fallback:Custom Error Handler
Handle all errors:Compression
For better performance, use the compress middleware:Complete Production Example
Hereβs a production-ready setup:Performance Optimization
1. Asset Fingerprinting
Ensure your build tool fingerprints assets:2. Code Splitting
Split code into smaller chunks:3. Tree Shaking
Import only what you need:4. Image Optimization
Optimize images before bundling:- Use WebP format for images
- Compress with tools like
imagemin - Use responsive images (
srcset) - Lazy load images below the fold
5. CSS Optimization
- Remove unused CSS (PurgeCSS, built into Tailwind)
- Minify CSS in build
- Inline critical CSS for faster first paint
Monitoring Production
Access Logs
Use the logger middleware:Metrics
Use Prometheus or custom metrics:- Request count
- Response times
- Error rates
- Cache hit rates
Next Steps
Configuration
Explore all configuration options
Caching
Deep dive into caching strategies
Security
Security best practices
Deployment
Build and deployment guide