Deploying Netlify Edge Functions: Low‑Latency Logic at the CDN Edge
Deploy Netlify Edge Functions to cut per‑request latency to sub‑10 ms. Learn how to write, deploy, measure, and monitor these edge‑executed functions—and when to choose them over traditional serverless functions.
30 Oct 2025, 12:14 UTC

Why Edge Functions Matter
Traditional Netlify serverless functions sit in a single region and add a few hundred milliseconds of network hop to every request. If your site needs per‑request logic—dynamic headers, A/B testing, or real‑time authentication—those extra milliseconds can hurt UX and SEO. Netlify Edge Functions run directly on the CDN edge nodes that already serve your static assets, cutting request latency to sub‑10 ms for most use cases.
What an Edge Function Looks Like
Edge Functions are written in JavaScript or TypeScript and exported as a handler that receives a Request and returns a Response. They live in netlify/edge-functions and are deployed via the Netlify CLI or the UI.
export async function handler(request) {
const now = new Date().toISOString();
return new Response(`Timestamp: ${now}`);
}
Because the function runs in a sandboxed runtime, you cannot access the local filesystem or long‑running background tasks. Instead, any persistent data must be fetched via HTTP or an SDK to an external service.
Deploying the Function
- Place the file in
netlify/edge-functions/timestamp.ts. - Run
netlify functions:deploy --edgefrom the project root. Permissions: Requires a Netlify team or personal account with the "Deploy" role. - Confirm deployment in the Netlify dashboard under "Edge Functions" or by running
netlify functions:list.- Expected output: a table listing
timestampwith statusActive.
- Expected output: a table listing
- Test the endpoint by visiting
https://.netlify.app/.netlify/edge-functions/timestampand inspecting the response headers. TheCache-Controlheader should indicate edge caching.
Measuring Latency
Open Chrome DevTools, navigate to the Network tab, and reload the Edge Function URL. Look for the latency column; values under 10 ms confirm the edge execution. Compare this to a regular serverless function endpoint to see the difference.
When to Use Edge vs. Serverless
| Use Case | Edge Function | Serverless Function |
|---|---|---|
| Dynamic headers or redirects per request | ✓ | ✓ (but higher latency) |
| A/B testing logic that must run before asset delivery | ✓ | ✓ (but slower) |
| Long‑running background jobs or heavy I/O | ✗ | ✓ (if in a dedicated region) |
Trade‑Offs and Limitations
- No filesystem access: Cannot read/write local files; use external storage APIs.
- Sandboxed runtime: CPU and memory are limited; keep logic under a few hundred milliseconds.
- Region availability: Some regions may still be in preview; check the Netlify docs for supported regions.
- Billing: Edge Functions are billed per invocation; high traffic can increase costs. Monitor usage in the "Edge Functions" dashboard.
Practical Checklist Before Rollout
- Verify the function appears in
netlify functions:listwith statusActive. - Inspect logs via
netlify logs --function timestampto confirm execution and latency. - Set environment variables in the Netlify UI; they are available in the function via
process.env.VAR_NAME. - Configure caching headers to control CDN cache invalidation.
- Set a budget threshold in Netlify’s usage dashboard to avoid unexpected charges.
Actionable Next Steps
1. Identify a per‑request logic that would benefit from <10 ms latency—e.g., a locale‑based redirect.
2. Write a minimal Edge Function, deploy it with --edge, and test latency.
3. Add the function to your routing rules in netlify.toml or via the UI.
4. Monitor performance and costs. If latency stays low and costs are acceptable, extend the function’s logic. If you hit the sandbox limits or need persistent storage, fall back to a traditional serverless function or external API.
Edge Functions give JAMstack developers a powerful tool to move logic closer to the user, but they come with constraints that require careful planning. By following the steps above, you can evaluate whether the edge is the right place for your next dynamic feature.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.