Optimizing Performance
- Run production builds with
NODE_ENV=productionso Marko strips debug checks and shortens internal IDs - Pass promises into
<await>rather than awaiting upstream to preserve streaming - Keep reactive state narrow and lazy-load heavy below-the-fold widgets
Marko's compiler applies streaming, fine-grained bundling, and compile-time reactivity automatically, so most templates are fast by default. When profiling reveals bottlenecks, focus on build configuration, async boundaries, client bundle scope, and serialized resume payloads.
Production Mode
Ensure production builds compile with NODE_ENV=production (or optimize: true in @marko/compiler). Production mode switches templates from the debug runtime to the optimized runtime, strips debug checks, and shortens internal template and scope identifiers.
Promise Passing
Start independent data fetches in parallel and pass their promises directly into <await> tags rather than awaiting them before rendering. Awaiting in a route handler or middleware holds back the entire HTML response, forfeiting streaming for static markup and <head> assets. See Promises over Awaiting.
Client Bundle Size
Because Marko bundles only interactive expressions, client JavaScript grows only with client-side state:
- Use the narrowest variable declaration that fits:
static constfor constants shared across instances,<const>for derived values, and<let>only for mutable state (see<let>vs<const>). - Choose
<show>when toggling bulky static markup that is already server-rendered so the browser does not bundle template creation code just to toggle visibility; choose<if>when hidden branches should not render on the server. - Defer heavy interactive components (charts, rich editors, below-the-fold widgets) with lazy loading (
with { load: "visible..." }orwith { load: "idle" }).
Reducing Hydration Data
Marko serializes only the values read by browser code, embedded inline in the HTML for resumability. Keeping reactive state lean shrinks both HTML transfer size and browser parse time:
- Pass only the fields a client interaction actually reads rather than whole database records into interactive tags or event handlers.
- Keep server-only values out of
$global.serializedGlobals. - See Serializable State for how shared references and streaming flushes serialize.
Profiling
On the server, profile template throughput with Node's --cpu-prof flag or the Node Inspector under NODE_ENV=production to separate rendering cost from upstream I/O latency.
In the browser, inspect bundle composition with Vite's bundle visualizer, view compiled client output in the Playground ("Client JS" tab), and measure interaction cost in browser DevTools.
Contributors
Helpful? You can thank these awesome people! You can also edit this doc if you see any issues or want to improve it.