Skip to content

x/frontend Primer

Beta — API is stable within a minor version. Check Release Posture and Extension Maturity before adopting in production.

Open this page after x/* Family when the change is clearly about serving frontend assets from a Go HTTP service: mounting a static directory, serving embedded assets compiled into the binary, configuring SPA fallback routing, or managing cache headers for precompressed files.

x/frontend provides static and embedded frontend serving helpers for explicit mounting. It is transport-only and has no opinion about the frontend framework or build output format.

  • you are mounting a filesystem directory as a static asset path in a Plumego service
  • you are serving embedded assets via embed.FS compiled into the binary with RegisterFS
  • you are configuring SPA fallback routing so that unknown paths serve index.html
  • you are setting cache headers and precompressed asset serving policy (Brotli, gzip)
  • you are configuring content security or cache-control headers for frontend asset responses
  • the change is about HTTP route matching or path parameter extraction — that belongs in router
  • the work is business-specific UI flows or product page logic — keep that in the frontend application
  • the change introduces core bootstrap ownership or application wiring — that belongs in core and app/routes.go
  • the work involves tenant-specific asset resolution or per-tenant theming

First files to read in the current repository

Section titled “First files to read in the current repository”
  1. x/frontend/module.yaml
  2. x/frontend/frontend.go
  3. x/frontend/mount.go
  4. x/frontend/config.go
  5. x/frontend/compression.go
Keep it in x/frontend when the work is aboutMove out when the work becomes
Mounting http.Dir or embed.FS at a path with SPA fallbackroute matching rules or path parameter extraction — use router
Cache-control and Expires header policy for asset responsesCDN-level or reverse-proxy cache configuration
Serving precompressed .br or .gz files when the client accepts thembusiness-specific content negotiation outside asset serving
Fallback to index.html for SPA client-side routingserver-side rendering or dynamic page generation
RegisterFS: serving caller-provided http.FileSystem values such as http.FS(embedFS)frontend build tooling or asset pipeline configuration

Serving frontend assets from a Go service is a common pattern but easy to wire incorrectly: hidden filesystem side effects, fallback policy baked into router rules, or cache headers scattered across handlers. x/frontend centralizes these concerns in explicit, transport-only helpers so that mounting stays visible in routes.go and cache policy stays reviewable.