Edge Side Includes (ESI) is a small XML-based markup language that instructs an edge server or reverse proxy to assemble a web page from separate fragments, each fetched and cached according to its own rules. In content delivery across the Internet, ESI allows a mostly static page to be served from an edge cache while a few personalized or fast-changing parts are fetched independently, so the page as a whole does not have to bypass the cache.
ESI was proposed in 2001 by a group of vendors led by Akamai and Oracle and submitted to the W3C as the ESI Language Specification 1.0. It never became a formal W3C recommendation, yet it remains supported, usually as a subset of the language, by Akamai, Fastly, Varnish Cache and several other proxies and CDN platforms.
How Edge Side Includes assembles a page
ESI works by moving page composition from the origin server to the edge. The origin returns a template that contains ESI tags instead of finished content in selected places. The edge server parses the template, issues separate subrequests for each included fragment, and stitches the responses into one HTML document before sending it to the browser.
Each fragment is an ordinary HTTP resource with its own URL and its own Cache-Control headers. A product description can be cached for a day, a price block for one minute, and a shopping cart summary not at all. The template itself can therefore stay in cache for a long time, which raises the cache hit ratio of the page even though parts of it change constantly.
Processing usually has to be explicitly enabled for a response. Origins typically signal it with the Surrogate-Control: content="ESI/1.0" header, and many platforms also require a configuration rule, because parsing every response for tags would waste CPU and could expose unintended behavior.
The steps below summarize the request flow at a single edge node.
| Step | Actor | What happens |
|---|---|---|
| 1 | Browser | Requests the page URL from the nearest point of presence |
| 2 | Edge server | Serves the cached template or fetches it from the origin |
| 3 | Edge server | Parses ESI tags and builds a list of fragment URLs |
| 4 | Edge server | Serves each fragment from cache or requests it from the origin |
| 5 | Edge server | Merges fragments into the template in document order |
| 6 | Browser | Receives one complete HTML response |
Core ESI elements and what they do
The ESI 1.0 specification defines a compact set of elements in the esi: namespace. In practice, the include element carries most of the workload, and many deployments use nothing else. Vendors differ in how many of the remaining elements and expression functions they implement.
| Element | Purpose | Typical support |
|---|---|---|
| esi:include | Fetches a fragment by URL and inserts it | Universal |
| esi:remove | Holds fallback content shown when ESI is not processed | Common |
| esi:comment | Adds a note that the edge strips from output | Common |
| esi:try / attempt / except | Defines an alternative if a fragment fails | Partial |
| esi:choose / when / otherwise | Selects content from conditions on cookies or headers | Partial |
| esi:vars | Substitutes variables such as cookie values | Partial |
| esi:inline | Embeds a fragment that can be cached separately | Rare |
The include element accepts an alt attribute with a secondary URL and an onerror="continue" attribute that tells the edge to drop the fragment silently instead of failing the whole page. Conditional logic relies on variables such as HTTP_COOKIE, HTTP_HOST or HTTP_ACCEPT_LANGUAGE, which allows simple personalization at the edge without a round trip to application code.
ESI compared with other composition techniques
Edge Side Includes is one of several ways to combine cacheable and dynamic content. Its distinctive trait is that assembly happens on the cache server, between the origin and the browser, using declarative markup rather than application code.
| Technique | Assembly location | Main advantage | Main drawback |
|---|---|---|---|
| Edge Side Includes | CDN edge or reverse proxy | Caches the page shell close to users | Limited logic and uneven vendor support |
| Server Side Includes | Origin web server | Simple and widely available | Origin must build every page |
| Client-side fetching | Browser via JavaScript | No special edge features needed | Extra round trips and layout shifts |
| Edge compute functions | Programmable edge runtime | Full logic in a general language | Higher complexity and execution cost |
| Full-page caching only | Edge cache | Fastest delivery for anonymous users | Cannot personalize cached pages |
ESI is often confused with Server Side Includes (SSI), which use a similar idea but run on the origin. ESI also overlaps with dynamic site acceleration, though that term describes network optimizations for uncacheable traffic rather than fragment assembly. Modern edge functions can reproduce ESI behavior, and some platforms now offer ESI as a library inside those runtimes rather than as a built-in parser.
When to use Edge Side Includes
ESI pays off when a page is largely shared across users but contains a few small regions that are personal or volatile. Typical cases include headers with a login state, regional price boxes, stock indicators and recently viewed lists. When most of the page is personal, the overhead of assembly outweighs the caching gain.
| Situation | Recommended approach | Reason |
|---|---|---|
| Static page with a small user widget | Use ESI for the widget | Template stays cached for all users |
| Catalog page with prices changing hourly | ESI with a short fragment TTL | Shell and prices expire independently |
| Fully personalized dashboard | Skip ESI | Little shared content to cache |
| Many fragments per page | Consolidate or use edge functions | Each fragment adds a subrequest |
| Platform without ESI support | Client-side fetching | Markup would be sent raw to browsers |
Good practice keeps the number of includes low, often fewer than ten per page, and gives every fragment explicit cache headers. Fragments should be designed so that a cache purge or cache tag invalidation can refresh one region without touching the template.
Limitations, risks and common mistakes
The most serious limitation is inconsistent implementation. Each vendor supports a different subset, nested include depth is capped, and expression syntax can vary, so templates written for one platform may break on another. Debugging is harder because the browser never sees the raw template.
Latency depends on the slowest fragment. Many processors fetch includes sequentially or with limited parallelism and cannot stream the page until a blocking fragment arrives. A fragment that misses cache and waits on a slow origin delays the entire response.
Security researchers have documented ESI injection attacks, in which untrusted input that reaches a processed response inserts ESI tags. Such tags can trigger server-side request forgery, bypass HttpOnly cookie protection or enable cross-site scripting. The essential safeguard is to escape user input and to enable ESI processing only on responses that are meant to contain it.
- Forgetting fallback content: without esi:remove, a misconfigured edge may show nothing in the fragment slot.
- Caching personal fragments: a cart fragment cached without the right cache key can leak data between users.
- Ignoring the Vary header: fragments that depend on language or cookies need correct variation rules.
- Testing only at the origin: the origin output contains tags, so tests must run through the edge.
Explained without jargon
Imagine a newspaper that prints the same front page for everyone but leaves a few blank boxes. At each local newsstand, a clerk fills those boxes with the weather, local scores or a note with the reader’s name. The newspaper does not reprint the whole page for every reader, and the boxes stay fresh.
Edge Side Includes works the same way for websites. Servers located near visitors keep a ready copy of the page layout and fill in only the small parts that change. The result is a fast page that still feels personal, without asking the main server to rebuild everything for each visit.
A typical use case
An online electronics retailer serves about two million product page views per day. Product descriptions and images change rarely, but prices update several times a day and the header shows each shopper’s cart count. Before ESI, the header made every page uncacheable, and the origin handled nearly all requests.
The engineering team splits each page into a template cached for 24 hours, a price fragment cached for 5 minutes, and a cart fragment marked private and fetched on every request. The cart include carries onerror="continue" so a slow cart service cannot block the page. After rollout, the edge serves roughly 90 percent of page bytes from cache, origin load drops sharply, and median page delivery time improves noticeably for shoppers in distant regions.