Edge-Side-Includes with Cloudflare Workers
Aug 20, 2018Stephane Nouvellon

Summary
This post introduces the implementation of Edge-Side-Includes (ESI) using Cloudflare Workers. It demonstrates how Workers can be used to dynamically fetch and merge dynamic content fragments into static pages at the edge, improving performance for pages with dynamic elements. The solution involves intercepting text-based responses, identifying ESI include blocks, fetching the content of these blocks via sub-requests, and then merging the static and dynamic parts before sending the final response to the visitor. The worker script utilizes TransformStream for efficient streaming of the response body and includes logic for handling ESI blocks and their source URLs.