esi-service-worker
v0.0.1
Published
ESI stream parser for service and cloudflare workers
Downloads
2
Maintainers
Readme
esi-service-worker
This package contains a minimal implementation of Edge Side Includes that run on both serviceworkers and cloudflare workers.
ESI compatibility
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
Implementation details
Most of the basic code infrastructure is in place. It can be easily extended with the part of the specs we want to implement.
How to use
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()
}
}