Static Sites & Deployment

Edge Function

Definition

An edge function is a serverless function deployed to every point of presence in a network instead of to a single region. Cloudflare Workers, Vercel Edge Functions, Netlify Edge Functions and AWS Lambda at Edge are the common implementations. Most run on a JavaScript engine rather than a container — typically V8 isolates — which is why they start in single-digit milliseconds instead of hundreds, and equally why the runtime is narrow: no file system, no long-lived connections, a restricted set of APIs and a CPU budget measured in tens of milliseconds per request. The usual job is to look at a request or a response as it passes and change it: add a security header, redirect by country, split an A/B test, read a cookie and pick a variant. Image processing, database joins and anything measured in seconds do not belong here.

Why It Matters

What you save is a round trip. A visitor in Singapore reaching a server in Ireland spends roughly 180 milliseconds each way before a line of code runs; the same decision made at the Singapore node answers in under 20. For a redirect or a header rewrite that round trip is essentially the whole response time, so the difference is plainly visible. The limits deserve equal weight. A CPU budget of 10 to 50 milliseconds rules out most of what you might be tempted to do, and exceeding it fails the request rather than slowing it. Edge functions are also the wrong answer when the result depends on a database in one region — you have moved the compute and left the data behind, and the round trip returns with interest.

How It Works

A request arrives at whichever point of presence is nearest the visitor. Before the CDN consults its cache, it runs whatever function you attached to that route, handing it the request. Your code can answer directly, alter the request and let it continue to cache or origin, or alter the response on its way back out. Because identical code is deployed everywhere, there is no region to pick and no instance count to manage — the platform spins up an isolate per request and discards it, usually inside 5 milliseconds. State is the real constraint: an isolate keeps nothing between requests, so anything shared must come from a distributed key-value store, and a write to that store takes time to reach every location, which means two visitors can briefly see different answers.

Real-World Example

A company hosts a product one-pager on 99helpers at lockwood-launch.99helpers.site and wants German visitors to land on the German version. Doing it with JavaScript in the page means the wrong content renders first and then jumps, which readers notice and measurement tools penalise. An edge function reads the country the network has already resolved for the connection and rewrites the path to /de/ before the cache lookup happens, so the correct page is the first response rather than the second. The function is about fifteen lines and runs in roughly a millisecond.

Common Mistakes

  • Treating it as a general backend — the CPU budget and the missing APIs stop most real work long before any timeout does
  • Querying a database in a single region from every node — the code moved to the edge, the data did not, and the latency comes straight back
  • Holding state in a variable between requests — isolates are discarded, and each location keeps its own anyway
  • Attaching a function to a route that could have been a plain file — every request now costs compute for an answer the cache already had

Related Terms

Put a file online in seconds

Drop in a document, an image, a page or a whole static website and share the link — free, with no build step and no server to set up.

Host a file free →