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 use responseProvider 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.

NameTypeDescriptionRequired
edgeworker-versionStringUnique identifier for the EdgeWorkers version.
bundle-versionIntegerBundle format version.
api-versionStringVersion of JavaScript API when the EdgeWorkers code was created.
descriptionStringPhrase describing the EdgeWorkers script function.
miscObjectInformation you can include in the manifest to identify the EdgeWorkers function.
invoke-for-edgeworker-clientsBooleanWhen set to true, it enables support for subWorkers. By default, this configuration setting is set to false.
configObjectAdditional, not required configuration, such as thelogging object.
loggingObjectContains information about the log delivery destination stream, and/or the default log level.
levelTrace, Debug, Info, Warn, or ErrorThe default JavaScript logging level applied to the EdgeWorkers code bundle. You can use this parameter to override the default log level, error.
schemaStringNot currently in use. Use v1 as a placeholder.
ds2idIntegerThe Data Stream 2 stream id to associate with the JavaScript logging data.
The stream needs to be active before you include it in the EdgeWorkers code bundle.
When you add the logging config setting to the bundle.json file, the ds2id is required.

📘

Limit edgeworker-version characters to alphanumeric, underscore, dash, dot, and tilde. The maximum length of the edgeworker-version is 32 characters.

{
   "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"
   }
}