esi-service-worker

0.0.1 • Public • Published

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

Package Sidebar

Install

npm i esi-service-worker

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

146 kB

Total Files

25

Last publish

Collaborators

  • sithmel