Skip to main content
Production mode is optimized for performance, security, and reliability. When you deploy your Mizu app, it serves pre-built static files with intelligent caching, compression, and security headers.

How Production Mode Works

In production, Mizu serves static files directly from the filesystem or embedded FS:
The flow:
  1. Browser requests a path
  2. Mizu checks if it’s an API route
  3. If no, check if a static file exists at that path
  4. If file exists β†’ serve it with appropriate cache headers
  5. If not β†’ serve index.html for SPA routing

Enabling Production Mode

Automatic Detection

Use auto-detection based on environment:
Set environment to production:

Explicit Production Mode

Force production mode:
Or with options:

Building Your Frontend

Before deploying, build your frontend:

Vite (React/Vue/Svelte)

Creates optimized files in dist/:
  • Minified JavaScript
  • Minified CSS
  • Optimized images
  • Asset fingerprinting (e.g., main.abc123.js)

Angular

Creates files in dist/my-app/browser/.

Next.js / Nuxt

Build Output Structure

A typical Vite build creates:
Key points:
  • 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 serve index.html to let the frontend router handle navigation.
Automatic fallback:
  • / β†’ 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)
The frontend router (React Router, Vue Router, etc.) then handles the routing.

Caching Strategy

Mizu applies intelligent caching based on file type and fingerprinting.

Default Cache Durations

How Hashing Works

Hashed filename (content hash in name):
If the file content changes, the hash changes:
Benefits:
  • Old version stays cached (doesn’t break users on old version)
  • New version has new filename (forces fresh download)
  • Can cache aggressively with immutable directive

Custom Cache Configuration

Override default cache durations:

Custom Pattern-Based Caching

Cache specific file types differently:
Cache logic:
  1. Check custom patterns first
  2. If no match, check if filename has hash
  3. If hashed β†’ use HashedAssets duration
  4. If unhashed β†’ use UnhashedAssets duration
  5. If HTML β†’ use HTML duration (or no-cache)

Security Headers

Mizu automatically adds security headers in production:
These protect against:
  • MIME sniffing attacks (nosniff)
  • Clickjacking (SAMEORIGIN)
  • XSS attacks (legacy protection)
  • Referrer leaking (privacy)

Disable Security Headers

If you’re using the helmet middleware:
This avoids duplicate headers.

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:
Why block them?
  • 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:
Benefits:
  • Single binary contains both backend and frontend
  • No need to deploy dist/ folder separately
  • Simpler deployment
  • Faster startup (no disk reads)
Trade-offs:
  • Larger binary size
  • Can’t update frontend without rebuilding
  • Need to rebuild for frontend changes
See Embedded Filesystems for details.

URL Prefix

Serve frontend from a subdirectory:
Routing:
  • / β†’ Go handler (not fronted)
  • /app β†’ dist/index.html
  • /app/about β†’ dist/index.html (SPA fallback)
  • /app/assets/main.js β†’ dist/assets/main.js
Frontend router config:

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:
This compresses responses with gzip or brotli, reducing transfer size by 60-80% for text files.

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:
Logs show all requests:

Metrics

Use Prometheus or custom metrics:
Track:
  • 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