This package contains a minimal implementation of Edge Side Includes that run on both serviceworkers and cloudflare workers.
See full specs here
This package only implements esi:include and esi:remove.
<esi:include src="/cgi-bin/date.cgi" />
<esi:remove> This is removed</esi:remove>
It doesn't implement:
- attributes on esi:includes
- Variable sostitutions
- recursion
Most of the basic code infrastructure is in place. It can be easily extended with the part of the specs we want to implement.
The package includes a prebundled version serviceworker.js
A serviceworker can also be implemented with:
import fetchAndStream from "esi-stream-parser"
self.addEventListener("fetch", onFetch)
function onFetch(event) {
event.respondWith(fetchAndStream(event.request))
// the following is implemented in Cloudflare workers
if ("passThroughOnException" in event) {
event.passThroughOnException()
}
}