Code bundle format
To create the EdgeWorkers bundle, you need a JavaScript source file called main.js
that contains event handler definitions for when to execute the code:
-
onClientRequest
. This event happens for every request as the request is received, before checking if a response is available in cache. -
onOriginRequest
. This event happens just before sending the request to the origin. -
onOriginResponse
. This event happens as the origin response is created. -
onClientResponse
. This event happens for every request just before the client response is sent. -
responseProvider
. This event happens if the response is not already found in cache. You can useresponseProvider
to generate dynamic responses from various content and API sources.
You also need to create a manifest file called bundle.json
that includes meta information as described in the table below.
Name | Type | Description | Required |
---|---|---|---|
edgeworker-version | String | Unique identifier for the EdgeWorkers version. | ✓ |
bundle-version | Integer | Bundle format version. | ✗ |
api-version | String | Version of JavaScript API when the EdgeWorkers code was created. | ✗ |
description | String | Phrase describing the EdgeWorkers script function. | ✗ |
misc | Object | Information you can include in the manifest to identify the EdgeWorkers function. | ✗ |
Limit
edgeworker-version
characters to alphanumeric, underscore, dash, dot, and tilde.
{
"edgeworker-version":"4.22.3",
"bundle-version":1,
"api-version":"0.3",
"description":"Language Redirect",
"misc":{
"author":"jsmith",
"git-commit":"4ce52c8ff4fdd1771e5347297ea5691b55c4f6ed",
"updated":"2027-09-23"
}
}
Updated about 1 year ago