Skip to main content
Mizu can serve static files such as images, CSS, JavaScript, and other assets. This is essential for web applications that need to deliver frontend resources alongside API responses.

Overview

Static file serving in Mizu supports multiple file sources:

Serving from a Local Directory

The simplest approach is serving files from a folder on disk:
With this configuration:

Directory Structure Example

Serving Embedded Files

For production deployments, embed static files directly into your Go binary using the embed package. This creates a single executable with no external file dependencies.

Understanding embed.FS

The //go:embed directive includes files at compile time:
The embed package preserves directory structure. Use fs.Sub() to remove the root directory prefix when serving.

SPA (Single Page Application) Support

Single page applications require all routes to return index.html so the frontend router can handle navigation.

Caching

Configure caching based on file types:

Development vs Production

Benefits of embedding:
  • Single binary deployment
  • No missing file issues
  • Faster startup (files already in memory)
  • Immutable content (great for containers)

Summary

Next steps

Frontend Integration

Serve React, Vue, and other SPAs.

Deployment

Production deployment strategies.