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
| Asset Type | Cache-Control | Duration |
|---|---|---|
Hashed files (main.abc123.js) | public, max-age=31536000, immutable | 1 year |
Unhashed files (logo.png) | public, max-age=604800 | 1 week |
| HTML files | no-cache, no-store, must-revalidate | None |
Source maps (.map) | no-cache | None |
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