Skip to content

sithmel/esi-service-worker

Repository files navigation

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()
  }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published