What is Mizu Frontend?
The frontend package handles the complete lifecycle of serving frontend applications: In Development:- Proxies requests to your dev server (Vite, webpack, etc.)
- Enables Hot Module Replacement (HMR) for instant updates
- Proxies WebSocket connections for real-time development features
- Shows helpful error pages when the dev server is down
- Serves optimized static files with intelligent caching
- Supports embedded filesystems for single-binary deployment
- Adds security headers automatically
- Implements SPA fallback routing for client-side navigation
- Handles asset fingerprinting and cache busting
Supported Approaches
Mizu supports two main approaches to building frontends:Single Page Applications (SPAs)
SPAs are JavaScript-heavy applications that render in the browser. The server sends a minimal HTML page, and JavaScript handles routing and rendering. Popular SPA Frameworks:- React - The most popular UI library with a massive ecosystem
- Vue - Progressive framework with excellent developer experience
- Svelte - Compiler-based framework with minimal runtime
- Angular - Full-featured framework from Google
- Preact - Lightweight React alternative
- Rich, interactive user interfaces
- Desktop-like web applications
- Apps that work well offline
- Applications with complex client-side state
Server-Rendered Applications
Server-rendered apps generate HTML on the server and send it to the browser. JavaScript is used sparingly for interactivity. Popular Server-Rendering Approaches:- HTMX - Hypermedia-driven approach with minimal JavaScript
- Alpine.js - Lightweight JavaScript for progressive enhancement
- Go Templates - Pure server-side rendering
- Content-heavy websites
- SEO-critical applications
- Apps that need to work without JavaScript
- Simpler applications with less interactivity
- Teams that prefer server-side logic
Hybrid Frameworks
Some frameworks support both approaches:- Next.js (React) - Server-Side Rendering, Static Generation, or SPA
- Nuxt (Vue) - Server-Side Rendering, Static Generation, or SPA
- SvelteKit (Svelte) - Server-Side Rendering or Static Generation
How It Works
Development Mode
When you run your app in development:- You make a request to
http://localhost:3000 - Mizu checks if itβs an API route (e.g.,
/api/*) - If not, Mizu proxies the request to your frontend dev server
- The dev server responds with the latest code
- HMR WebSocket connections are also proxied for live reload
Production Mode
When you deploy your app:- You build your frontend (e.g.,
npm run build) - Mizu serves the built files from the
distfolder - API routes are handled by your Go handlers
- Frontend routes fall back to
index.htmlfor SPA routing - Assets are cached aggressively based on their fingerprint
Auto-Detection
Mizu can automatically detect whether to run in development or production mode based on environment variables:MIZU_ENV, GO_ENV, or ENV environment variable:
productionorprodβ Production mode- Anything else β Development mode
Choosing an Approach
Not sure which approach to use? Hereβs a decision guide:| Question | SPA | Server-Rendered |
|---|---|---|
| Need rich interactivity? | β Yes | β οΈ Limited |
| SEO is critical? | β οΈ Requires SSR | β Yes |
| Team knows JavaScript frameworks? | β Yes | β οΈ Maybe |
| Simple CRUD app? | β οΈ Overkill | β Perfect |
| Offline support needed? | β Yes | β No |
| Fast initial page load? | β οΈ Slower | β Faster |
| Large team? | β Good | β οΈ Depends |
- Start simple: If youβre unsure, start with HTMX or Alpine.js
- Go SPA: If you need a desktop-like experience or complex state
- Hybrid approach: Use HTMX for most pages, React for complex features
Quick Comparison
HTMX Example
React Example
- HTMX: Server sends HTML, minimal JavaScript
- React: Server sends JSON, React renders HTML