Content transformation

Review these common questions about EdgeWorkers content transformation. To learn more, review the the Response content transformation tutorial in this guide.

What are the benefits of using EdgeWorkers to transform content?

You can put your own transformation logic in place. To implement advanced metadata you need support from Akamai.

Unlike ESI, EdgeWorkers functions can transform content by streaming it. Streaming lets the EdgeWorkers function respond to the client with the initial content, before it receives the full content from the origin. EdgeWorkers delivers the initial cacheable content at the beginning of the response while waiting on non-cacheable content later in the response. This can improve Time to First Byte (TTFB).

If I add EdgeWorkers to a URL, can my code read the response body?

When you insert an EdgeWorkers function "inline" with an existing request or response, it cannot read the response body directly. There are four different event handlers that can execute when the EdgeWorkers function is inline with a request or response. These are onClientRequest, onOriginRequest, onOriginResponse, and onClientResponse. None of these event handlers have access to the response body.

responseProvider can produce large responses. However, when added to an EdgeWorkers function, responseProvider replaces the origin request.

How can EdgeWorkers modify content?

Response modification is the combination of two separate capabilities:

  • The ability to generate an HTTP response from responseProvider.
  • The ability to act as an HTTP client and make outbound sub-requests from the EdgeWorkers code.

By combining these capabilities, you can design an EdgeWorker function that:

  • Is invoked on a URL.
  • Makes a sub-request to a second URL.
  • Reads the response content from the sub-request.
  • Modifies the response content as needed.
  • Returns the modified content back to the end-user.

The end result is the equivalent of modifying the body content.

Can I cache the request for the "original" content?

Yes, caching the request for the "original" content eliminates the need to execute the JavaScript logic every time. The sub-request to fetch the original content must go through an Akamai edge hostname, and metadata is then executed for the request. As a result, you can enable caching in Property Manager on the sub-requests' path.

Can I cache the content generated by the EdgeWorkers function?

Yes, you can cache the EdgeWorkers content so you don't have to execute the JavaScript logic every time. You can use Property Manager to configure caching on the URL that is delivered by the EdgeWorkers function. The responseProvider function acts like the origin, and can be cached just as any other origin request.

Can I use the same URL for the EdgeWorkers code and origin to "transparently" modify the content of an existing URL?

This is also possible. The EdgeWorkers code can make an HTTP sub-request to the same URL that initiated the EdgeWorkers execution. EdgeWorkers are not allowed to execute on sub-requests, so you don't have to worry about an infinite loop. There are some nuanced implementation details, especially if caching of the original and transformed content is required. For more information, refer to the Response content transformation topic in this guide.

Which limits apply to requests that are transformed by EdgeWorkers?

All EdgeWorkers limits apply, including CPU time, wall time, and memory limits. Additionally, the request to retrieve the original content must complete within the maximum wall time allowed per HTTP sub-request. Refer to the Resource tier and Product limits for more information.