Edge functions are short-lived functions executed on servers distributed across a provider's global network, rather than in one central data center. They run close to the visitor and can inspect, modify or answer an HTTP request before it reaches your origin server.
Why it matters
Placing logic near users cuts round-trip latency. Typical uses include redirects, A/B test assignment, geolocation-based content, header rewriting, authentication checks and light personalization of cached pages. Providers such as Cloudflare Workers, Vercel and Netlify offer this model.
The trade-off is a restricted runtime. Many platforms run a lightweight JavaScript or WebAssembly environment with limited execution time, memory and Node.js APIs, and database access may add back the latency you saved if the data lives far away.
Example
export default {
async fetch(request) {
const url = new URL(request.url);
if (url.pathname === "/old") {
return Response.redirect("https://example.com/new", 301);
}
return fetch(request);
},
};
The function redirects one path at the edge and forwards everything else to the origin.
Common mistakes
- Assuming full Node.js compatibility and importing libraries that need the filesystem.
- Calling a distant database on every request.
- Forgetting that edge bugs can break the whole site before your origin logs anything.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.