Code Examples

Icon Card background
HTML Rewriter

Leverage EdgeWorkers html-rewriter to efficiently generate dynamic HTML content by combining JSON data from an API endpoint with an HTML template. Additionally, if the request is made by a logged-in user, a discount code will be dynamically incorporated into the rendered document. By performing these operations at the Edge with EdgeWorkers, we enhance site performance, offload server resources, and unlock SEO advantages. The template, JSON data, and rendered content can all be efficiently cached at the Edge, further optimizing response times and improving the overall site experience.

View Case
Icon Card background
JA3 Fingerprinting

Calculates JA3 Fingerprint using EdgeWorkers. TLS fingerprinting is a technique that associates a TLS library with parameters from a TLS ClientHello via a database of curated fingerprints to identify malware and vulnerable applications for better network visibility. The JA3 algorithm takes a collection of settings from the SSL “ClientHello” such as SSL/TLS version, accepted cipher suites, list of extensions, accepted elliptical curves/formats, and others. For compactness, the JA3 string is hashed with MD5. This EdgeWorker calculates JA3 Fingerprint to help customers deny requests from services with suspicious JA3 Fingerprints and credentials, without contacting origin servers even on cacheable contents.

View Case
Icon Card background
Multivariate Testing

Enables multivariate testing where multiple tests are executed simultaneously. A single variant is selected for each test, and variants are randomly assigned to new users, with each selected variant stored in a cookie and passed to the origin in a query string parameter. The probability of choosing each variant can be configured by adjusting the weight of each variant. Variants can be forced via a query string parameter for easy testing. Custom actions can be executed in the request and/or response phase of each variant, such as routing a variant to a different origin or constructing a response at the edge.

View Case
Icon Card background
Origin Error Handling

Translates a HTTP 503 status code (service unavailable) from an overloaded origin into an HTML page presenting the information in a more user-friendly way. It includes JavaScript to retry after the period indicated by the ‘Retry-After’ header from the origin, if present. Otherwise, it retries after a default number of seconds. Configuring the property to cache HTTP error responses, even for a short duration, makes sense for dynamic content.

View Case
Icon Card background
Product URL Redirects

Note the URL path changing from /sku/483D5F/reviews to products/straight-fit-denim-jeans/reviews

This example uses EdgeWorkers + EdgeKV to extract a query string product SKU from an incoming URL, match it against a SKU stored in a KV database, and properly redirect the browser to the new product page.

View Case
Icon Card background
Promo Code Validation

The Promo Code Validation example demonstrates how you can use EdgeWorkers and EdgeKV to validate promo codes at the Edge. A list of promo codes with valid date ranges is stored in EdgeKV. It also shows how you could use the getJson() helper method.

View Case
Icon Card background
Register User Details

Demonstrates how you can use EdgeWorkers and EdgeKV to collect user details. It also shows how you could use the putJson() helper method.

Note: Please copy the ‘key’ value from the output if you wish to verify the entered details in the Search User example.

View Case
Icon Card background
Response Manipulation

Demonstrates how an EdgeWorker can modify an HTML response stream by adding content to the response. The example adds a script to the page just before the closing head tag.

View Case
Icon Card background
Search User Details

The example demonstrates how you can use EdgeWorkers and EdgeKV to search for specific user details. It also shows how you could use getJson() helper method.

Note : This is an extension of User Registration use case. You would need the key value from the User Registration use case if you want to verify the details.

View Case
Icon Card background
Store Locator

Implements a microservice store locator API call that returns the two stores nearest to the provided latitude and longitude.

Note: Latitude and Longitude values are hardcoded for demo purposes.

View Case
Icon Card background
Traffic Allow

Implements an allow list depending on the geographic locale of the end user. If the user is arriving from United States embargoed countries, a 403 deny will occur.

View Case