# Server and edge composition

Each team serves HTML fragments from its own service. A server or CDN edge stitches them into one page before it reaches the browser, so visitors and crawlers get complete HTML on the first response.

## How it works

1. **Request hits the edge.** The browser requests a page. A server or CDN edge receives it and reads the page template, which marks each team's slot with an include.
2. **Fetch team A's fragment.** For each include, the composer requests HTML from the owning team's service, such as /fragments/search.
3. **Fetch team B's fragment.** Team B's fragment is fetched the same way. If it fails, the composer can use fallback content or leave the slot out.
4. **One page to the browser.** The composer sends one assembled HTML page. Any interactive parts still need their own scripts in the browser.

## Try it

**Demo: Performance waterfall.**

The same page is built three ways, here with three team apps. With iframes, every app is a full page with its own HTML, its own copy of React and its own code: three apps mean three Reacts, 257 KB in all, and the page is interactive at about 750 ms, while first paint at 220 ms shows only the shell. With Module Federation, one shell and one shared React load first, then each remote adds a small entry file and a chunk: 149 KB, interactive at about 600 ms, with the slots empty at first paint. With server composition, the server fetches every fragment before it sends one composed page, so the content is already in the HTML at first paint, around 270 ms, and the browser only loads styles, React and small hydration scripts: 117 KB, interactive at about 470 ms, with the fragment fetches now happening on your servers. The model fetches fragments in parallel, as nginx SSI does; Fastly's ESI processes includes one after another, so there every fragment adds to the wait. The model and its numbers are illustrative, not a benchmark.

Takeaway: Every approach moves the cost somewhere. iframes download a framework per app, federation adds round trips per remote, and server composition moves the work to your servers. Measure the page your users actually load.

## Pros

- The first response is complete HTML, which is good for first paint and for crawlers.
- Each team owns and deploys the service that renders its fragment.
- Fragments can be written in any server-side language or framework.

## Cons

- Needs server or CDN infrastructure that processes includes, and ownership of it.
- Interactivity is not solved: fragments that need client-side code still have to load and coordinate scripts.
- A slow fragment can hold up the whole response unless it has a timeout or fallback.

## Best when

- Content-heavy, SEO-critical sites such as e-commerce or publishing.
- Pages that are mostly server-rendered, with small islands of interactivity.
- Teams that already run their own backend services.

## Avoid when

- Highly interactive app-like interfaces where most work happens in the browser.
- You have no platform team to run and monitor the composing layer.
- Fragments need to share a lot of client-side state.

## In code

`page-template.html (processed at the edge)`

```html
<html>
  <body>
    <!-- Team A owns the header and search -->
    <esi:include src="https://team-a.example.com/fragments/header" />

    <main>
      <!-- Team B owns the cart. If src fails, alt is tried; if both fail,
           onerror="continue" drops the include instead of failing the page -->
      <esi:include src="https://team-b.example.com/fragments/cart"
                   alt="/fragments/cart-fallback" onerror="continue" />
    </main>
  </body>
</html>
```

## Ratings

_Editorial judgement for a typical team, from 1 to 5._

- **Team independence: 4/5** (higher is better). Each team deploys the service that renders its fragment, and the composer includes whatever it currently serves.
- **Runtime performance: 4/5** (higher is better). The browser gets one complete page without client-side assembly, but every fragment fetch adds to the server's response time.
- **Complexity: 4/5** (lower is simpler). You run and monitor a composing layer, handle timeouts and fallbacks, and still coordinate client-side scripts.
- **SSR / SEO support: 5/5** (higher is better). Composition happens on the server or edge, so the first response is already complete HTML.
- **Tech-agnostic: 5/5** (higher is better). The composer only sees HTML, so each team can render its fragment with any server technology.
- **Isolation: 3/5** (higher is better). A failing fragment can be replaced by fallback content, but once assembled, fragments share one page, its styles and its scripts.
- **UX consistency: 3/5** (higher is better). Fragments land in one page, but each team renders its own markup, so a consistent look depends on a shared design system.
- **Tooling maturity: 3/5** (higher is better). SSI and ESI are long established and supported by common servers and CDNs, but support for ESI features varies by vendor.

## Tooling and ecosystem

There are two common include mechanisms, and neither has versions to track. **Server Side Includes (SSI)** run on the origin server or a reverse proxy. In nginx, `ngx_http_ssi_module` processes `<!--# include virtual="/fragments/cart" -->` once `ssi on;` is set, and its non-standard `stub` parameter names fallback content for an empty or failed include ([nginx docs](https://nginx.org/en/docs/http/ngx_http_ssi_module.html)). **Edge Side Includes (ESI)** run on a CDN. The [ESI Language Specification 1.0](https://www.w3.org/TR/esi-lang/) is a 2001 W3C Note, published for discussion and not a W3C recommendation, from Akamai, Oracle and others. It defines `<esi:include src alt onerror>`. With `onerror="continue"`, an include that fails is removed silently.

Vendors implement different subsets of ESI. As of November 2026, Fastly documents only `include` (with `src`), `comment` and `remove`, with at most 5 levels of nesting and 256 includes per page, processed one after another ([Fastly docs](https://www.fastly.com/documentation/reference/vcl/statements/esi/)). Check your CDN's documentation before relying on any ESI attribute. Frameworks can also compose fragments on the server in application code. That moves the same trade-offs into a service that your teams run.

## Sources

- [ESI Language Specification 1.0](https://www.w3.org/TR/esi-lang/), Mark Tsimelzon et al. · W3C (Note)
- [Module ngx_http_ssi_module](https://nginx.org/en/docs/http/ngx_http_ssi_module.html), nginx.org
- [esi (VCL statement)](https://www.fastly.com/documentation/reference/vcl/statements/esi/), Fastly
- [Micro Frontends – extending the microservice idea to frontend development](https://micro-frontends.org/), Michael Geers · micro-frontends.org
- [Micro Frontends](https://martinfowler.com/articles/micro-frontends.html), Cam Jackson · martinfowler.com

https://microfrontends.dev/approaches/server-and-edge-composition