Edge Side Includes

Also known as: ESI

On this page 7

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.

StepActorWhat happens
1BrowserRequests the page URL from the nearest point of presence
2Edge serverServes the cached template or fetches it from the origin
3Edge serverParses ESI tags and builds a list of fragment URLs
4Edge serverServes each fragment from cache or requests it from the origin
5Edge serverMerges fragments into the template in document order
6BrowserReceives one complete HTML response
Edge Side Includes request flow at one edge node

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.

ElementPurposeTypical support
esi:includeFetches a fragment by URL and inserts itUniversal
esi:removeHolds fallback content shown when ESI is not processedCommon
esi:commentAdds a note that the edge strips from outputCommon
esi:try / attempt / exceptDefines an alternative if a fragment failsPartial
esi:choose / when / otherwiseSelects content from conditions on cookies or headersPartial
esi:varsSubstitutes variables such as cookie valuesPartial
esi:inlineEmbeds a fragment that can be cached separatelyRare
Main elements of the ESI 1.0 language

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.

TechniqueAssembly locationMain advantageMain drawback
Edge Side IncludesCDN edge or reverse proxyCaches the page shell close to usersLimited logic and uneven vendor support
Server Side IncludesOrigin web serverSimple and widely availableOrigin must build every page
Client-side fetchingBrowser via JavaScriptNo special edge features neededExtra round trips and layout shifts
Edge compute functionsProgrammable edge runtimeFull logic in a general languageHigher complexity and execution cost
Full-page caching onlyEdge cacheFastest delivery for anonymous usersCannot personalize cached pages
Where page fragments are assembled in common techniques

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.

SituationRecommended approachReason
Static page with a small user widgetUse ESI for the widgetTemplate stays cached for all users
Catalog page with prices changing hourlyESI with a short fragment TTLShell and prices expire independently
Fully personalized dashboardSkip ESILittle shared content to cache
Many fragments per pageConsolidate or use edge functionsEach fragment adds a subrequest
Platform without ESI supportClient-side fetchingMarkup would be sent raw to browsers
Deciding whether ESI suits a page

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.