Skip to main content
A standalone script handles the request itself. It serves dynamic content, runs your logic, and shapes the response at the edge, which in many cases means you don’t need an origin server at all. Running that close to the user keeps latency down, and a script handles many requests at once.

Use cases

  • Serve REST APIs and microservices straight from the edge
  • Generate dynamic UIs and landing pages based on user interactions or geolocation
  • Build AI-powered endpoints that process images, run chat completions, or generate embeddings
  • Back a static frontend with contact forms, webhooks, and data submissions
  • Call external APIs to send emails, transform data, or integrate with third-party services

The serve function

The serve function starts an HTTP server that listens for incoming requests and handles them using the provided handler function.

Function signature

Handler

The handler function receives a standard Request object and must return a Response or Promise<Response>.

Before cache execution

Preview Standalone scripts act as the origin for their Pull Zone, so by default they only execute when the cache is missed. If your Pull Zone is configured to execute scripts before cache, your script runs on every request, before the cache lookup.
You can enable it in your Pull Zone under General > Origin > Run script before cache, or directly in the script settings. Learn more about before cache execution.

Example

This example runs an A/B test based on a custom header:

Local development

You can run standalone scripts locally using Deno:
Test with curl:
Last modified on August 17, 2026