Why is Marko Fast?
- Zero-JS by default with fine-grained bundling
- Targeted compilation for server and browser
- First-class HTML streaming
- Compile-time reactivity and resumability
Marko achieves tiny client bundles, high-throughput SSR (1, 2), and fast DOM updates by moving work out of runtime JavaScript and into the compiler. Five architectural decisions drive this performance.
Targeted Compilation
The compiler generates two separate outputs per template: one for the server and one for the browser (inspect both live in the Playground under "Server JS" and "Client JS").
Server Compilation
Virtual DOM renderers build an in-memory tree first and serialize it to HTML in a second pass. Marko compiles templates into single-pass string concatenation writing straight to an HTML stream, eliminating intermediate tree allocations and enabling HTML streaming natively.
Client Compilation
After fine-grained bundling, browser output includes only serialized state, event handlers, <script> effects, and a tree-shaken subset of runtime helpers. Compile-time reactivity removes the need for a JavaScript DOM mirror.
Runtime Coordination
Server HTML embeds compact markers and serialized state. Browser code reads those markers to resume directly from the existing DOM without re-executing server work. See Targeted Compilation.
HTML Streaming
Marko flushes HTML to the browser as chunks finish rendering rather than buffering the whole page:
// Flushes immediately
<h1>${input.title}</h1>
<section>
<${input.content}/>
</section>
// Streams when ready
<await|recommendations|=fetchRecommendations(input.id)>
<ul>
<for|item| of=recommendations>
<li>${item.title}</li>
</for>
</ul>
</await>export interface Input {
title: string;
content: Marko.Body;
id: string;
}
// Flushes immediately
<h1>${input.title}</h1>
<section>
<${input.content}/>
</section>
// Streams when ready
<await|recommendations|=fetchRecommendations(input.id)>
<ul>
<for|item| of=recommendations>
<li>${item.title}</li>
</for>
</ul>
</await>// Flushes immediately
h1 -- ${input.title}
section
${input.content}
// Streams when ready
await|recommendations|=fetchRecommendations(input.id)
ul
for|item| of=recommendations
li -- ${item.title}export interface Input {
title: string;
content: Marko.Body;
id: string;
}
// Flushes immediately
h1 -- ${input.title}
section
${input.content}
// Streams when ready
await|recommendations|=fetchRecommendations(input.id)
ul
for|item| of=recommendations
li -- ${item.title}Marko has supported HTML streaming since 2014. See HTML Streaming.
JS Scales from Zero
Static markup compiles to zero browser JavaScript even inside the same template as interactive controls, and server work is never re-run in the browser.
Fine-Grained Bundling
The compiler analyzes templates at the expression level rather than component-level islands:
<h1>${input.product.name}</h1>
<p>${input.product.description}</p>
<div>Price: $${input.product.price}</div>
<let/quantity=1>
<button onClick() {
quantity--;
}>
-
</button>
<span>${quantity}</span>
<button onClick() {
quantity++;
}>
+
</button>export interface Input {
product: {
name: string;
description: string;
price: number;
};
}
<h1>${input.product.name}</h1>
<p>${input.product.description}</p>
<div>Price: $${input.product.price}</div>
<let/quantity=1>
<button onClick() { quantity-- }>-</button>
<span>${quantity}</span>
<button onClick() { quantity++ }>+</button>h1 -- ${input.product.name}
p -- ${input.product.description}
div -- Price: $${input.product.price}
let/quantity=1
button onClick() {
quantity--;
} -- -
span -- ${quantity}
button onClick() {
quantity++;
} -- +export interface Input {
product: {
name: string;
description: string;
price: number;
};
}
h1 -- ${input.product.name}
p -- ${input.product.description}
div -- Price: $${input.product.price}
let/quantity=1
button onClick() { quantity-- } -- -
span -- ${quantity}
button onClick() { quantity++ } -- +When server-rendered, the browser receives only the two click handlers and the <span> text update; none of the product heading, description, or price rendering logic ships to the client. See Fine-Grained Bundling.
Resumability
Traditional SSR relies on hydration, re-executing component code in the browser to recreate state and wire listeners. Marko skips hydration: client code deserializes only needed state, attaches delegated listeners, and locates target DOM nodes directly via server markers.
Tree-Shakeable Runtime
Compiled templates import only the specific runtime helpers they use:
<let/color="red">
<div style={ "background-color": color }>Content</div>let/color="red"
div style={ "background-color": color } -- Contentimport { _attr_style_item } from "marko/dom";
// ...rest of compiled outputBundlers tree-shake unused helpers away so unused language features add zero bytes.
Compile-Time Reactivity
Dependency graphs resolve at compile time:
<let/count=0>
<const/doubled=count * 2>
<button onClick() { count++ }>${count} × 2 = ${doubled}</button>let/count=0
const/doubled=count * 2
button onClick() { count++ } -- ${count} × 2 = ${doubled}The compiler emits a pre-computed update sequence for count that recalculates doubled and updates both text nodes directly, with no runtime dependency tracking.
Performance by Default
Marko's language design makes fast patterns the natural path (the pit of success): async rendering streams automatically, static expressions stay on the server without annotations, and reactive updates are compiled ahead of time. Refined in production since 2014, these architectural choices keep both SSR latency and browser bundles lean as applications grow.
Further Reading
Contributors
Helpful? You can thank these awesome people! You can also edit this doc if you see any issues or want to improve it.