Inferensys

Glossary

Edge-Side Includes (ESI)

Edge-Side Includes (ESI) is a simple markup language that instructs an edge server to assemble a web page from multiple fragments, each with its own independent cache policy, before delivering the final result to the user.
Developer demonstrating multi-agent tool use, agent tool selection interface on laptop, casual tech demo moment.
DYNAMIC CONTENT ASSEMBLY

What is Edge-Side Includes (ESI)?

A markup language for assembling dynamic web pages at the CDN edge by including fragments with independent cache policies.

Edge-Side Includes (ESI) is a markup language that enables dynamic content assembly at the CDN edge by instructing edge servers to include content fragments with different cache policies into a single page. It solves the problem of caching highly dynamic pages by allowing a page's static shell to be cached separately from its personalized or time-sensitive components.

ESI tags are embedded in HTML and processed by an ESI processor on the edge server. Common directives include <esi:include> to fetch a fragment, <esi:choose> for conditional logic, and <esi:try> for fallback handling. This architecture decouples content delivery from content generation, drastically reducing origin server load and improving time-to-first-byte (TTFB) for complex, personalized web applications.

Core Mechanisms

Key Features of ESI

Edge-Side Includes (ESI) is a simple markup language that enables dynamic content assembly at the CDN edge. It instructs edge servers to compose a single page from multiple fragments, each with its own independent cache policy.

01

Fragment Assembly

The core mechanism of ESI is the ability to decompose a web page into discrete, cacheable fragments. An ESI processor on the edge server parses the base template and fetches each referenced fragment, assembling the final HTML response on the fly. This allows a page with a Time-To-Live (TTL) of 24 hours to include a personalized shopping cart with a TTL of 0 seconds.

  • esi:include tag fetches content from a defined source URL
  • esi:inline tag allows content to be embedded directly within the markup
  • Fragments can be recursively nested, enabling complex assembly logic
02

Exception Handling & Fallbacks

ESI provides robust fault tolerance through built-in exception handling. If a fragment's origin server is unavailable or times out, the edge server can serve a stale-while-revalidate version or a predefined fallback resource, preventing a single backend failure from breaking the entire page.

  • esi:try block defines a primary fragment request
  • esi:attempt specifies alternative fallback sources
  • esi:except handles the final failure state gracefully
  • Default timeout behavior can be configured per fragment
03

Conditional Inclusion Logic

ESI supports basic conditional logic based on HTTP request headers, enabling context-aware assembly without hitting the origin server. An edge server can include different fragments based on a user's device type, geolocation, or authentication state by evaluating variables in the incoming request.

  • esi:choose acts as a switch statement
  • esi:when tests a condition against a header or variable
  • esi:otherwise provides a default branch
  • Common use case: serving a mobile header fragment vs. a desktop header fragment based on the User-Agent header
04

Variable Substitution

ESI allows dynamic string substitution within fragments using variables derived from HTTP headers or explicitly set by the edge server. This enables personalization at the edge without requiring a unique fragment for every user. A single cached fragment can display a user's name or a session-specific token.

  • $(HTTP_HEADER{name}) syntax reads request headers
  • $(ESI_VARIABLE{name}) references server-defined variables
  • Commonly used to inject CSRF tokens or user greetings into otherwise static, highly cacheable HTML chunks
05

Cache Policy Granularity

The primary architectural benefit of ESI is the ability to assign independent cache policies to each fragment. A news article body can be cached for hours, while a "Top Stories" sidebar is cached for minutes, and a user-specific "Continue Reading" bar is never cached. This maximizes cache hit ratios while preserving dynamism.

  • Fragment TTLs are controlled by standard HTTP Cache-Control headers from the fragment's origin
  • Enables a hole-punching strategy for highly dynamic content within static templates
  • Dramatically reduces origin server load by caching the page shell and recomposing only the volatile pieces
06

Surrogate Key Invalidation

ESI integrates with surrogate key (or cache tag) systems for precise cache invalidation. When a piece of content changes in the CMS, a single API call can purge all fragments associated with that content's unique key across the entire CDN, without needing to track every URL where it appears.

  • A product description fragment can be tagged with a key like prod-12345
  • When the product's price updates, a purge request for prod-12345 instantly invalidates all cached instances
  • Eliminates the need for full cache flushes or complex URL-based purging patterns
EDGE-SIDE INCLUDES

Frequently Asked Questions

Clear, technically precise answers to the most common questions about the Edge-Side Includes (ESI) markup language and its role in dynamic content assembly at the CDN edge.

Edge-Side Includes (ESI) is a markup language and edge-processing specification that enables dynamic web page assembly directly on a Content Delivery Network (CDN) edge server. It works by allowing an origin server to deliver a page template containing simple XML-based tags, such as <esi:include>, which instruct the edge server to fetch and stitch together content fragments from different sources. Each fragment can have its own independent caching policy, meaning a highly dynamic shopping cart can be assembled alongside a statically cached product description. The edge server parses the template, resolves all includes, and delivers the fully composed HTML to the client, dramatically reducing origin server load and perceived latency.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.