Website Load Optimization for Different Regions (Edge Computing)
Edge Computing transfers part of the calculations from the central server to CDN edge nodes. Instead of every request traveling to the data center in Moscow, it's processed on the nearest Edge node to the user — in Novosibirsk, Berlin, or Tokyo.
What can run on Edge
| Task | Edge Solution | Provider |
|---|---|---|
| A/B tests | Cloudflare Workers | Cloudflare |
| Locale detection and redirects | Edge Middleware | Vercel, Cloudflare |
| Geo-based personalization | Workers KV | Cloudflare |
| JWT authorization | Edge Functions | Cloudflare, Netlify |
| Static page SSR | Durable Objects | Cloudflare |
| Image optimization | Image Resizing | Cloudflare Pro |
Cloudflare Workers: geo-personalization
// workers/geo-personalization.js
export default {
async fetch(request, env) {
const country = request.cf.country;
const city = request.cf.city;
// Get response from origin
const response = await fetch(request);
const html = await response.text();
// Substitute regional content
const personalized = html
.replace('{{COUNTRY}}', country)
.replace('{{SHIPPING_NOTICE}}', getShippingNotice(country))
.replace('{{CURRENCY}}', getCurrency(country));
return new Response(personalized, {
headers: response.headers,
status: response.status,
});
}
};
function getShippingNotice(country) {
const notices = {
'RU': 'Free shipping in Russia from 3,000 ₽',
'DE': 'Free shipping from €50',
'US': 'Free shipping on orders over $50',
};
return notices[country] ?? 'Free international shipping';
}
Vercel Edge Middleware: redirects and localization
// middleware.ts (Next.js)
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export function middleware(request: NextRequest) {
const url = request.nextUrl.clone();
// Geo-based language redirect
const country = request.geo?.country ?? 'US';
const locale = countryToLocale(country);
if (url.pathname === '/') {
url.pathname = `/${locale}`;
return NextResponse.redirect(url, { status: 302 });
}
// Edge A/B testing
const bucket = request.cookies.get('ab_bucket')?.value
?? (Math.random() < 0.5 ? 'a' : 'b');
const response = NextResponse.next();
response.cookies.set('ab_bucket', bucket, { maxAge: 86400 * 30 });
response.headers.set('X-AB-Bucket', bucket);
return response;
}
export const config = {
matcher: ['/', '/(ru|en|de|fr)/:path*'],
runtime: 'edge', // executes on Edge, not on Node.js server
};
Edge KV Storage: regional data cache
Cloudflare Workers KV is a global key-value store with replication to all Edge nodes. Read latency < 1ms:
// Cache pricing data by region
async function getRegionalPricing(country, env) {
const cacheKey = `pricing:${country}`;
const cached = await env.PRICING_KV.get(cacheKey, 'json');
if (cached) return cached;
// Request from origin
const pricing = await fetch(`https://api.example.com/pricing?country=${country}`)
.then(r => r.json());
// Cache for 1 hour
await env.PRICING_KV.put(cacheKey, JSON.stringify(pricing), { expirationTtl: 3600 });
return pricing;
}
Durable Objects: SSR on Edge
For sites with SSR (Next.js, Nuxt, Remix), Cloudflare Pages + Workers allows running server-side rendering on Edge nodes without a central server:
User (Tokyo) → Cloudflare Edge Tokyo
↓ SSR here, not in Moscow
Rendered HTML → User
TTFB latency reduces from 300–500ms to 50–80ms for users in regions.
Metrics to measure effectiveness
Before and after implementing Edge optimization:
- TTFB (Time to First Byte) — key metric, should decrease
- FCP (First Contentful Paint) — affects perceived speed
- Core Web Vitals by region in Google Search Console
Measurement tools
# Measure TTFB from different regions via curl
curl -w "\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n" \
-o /dev/null -s https://example.com
# Or via WebPageTest with region
# https://www.webpagetest.org — select Test Location: Moscow, Frankfurt, Singapore
Timeline
Basic Edge optimization (redirects, geolocation via Cloudflare Workers): 3–5 days. SSR migration to Edge (Cloudflare Pages + Workers): 10–15 days.







