Smart Placement Probe
Demonstrate Workers Smart Placement by probing origin latency from the serving colo - place compute near your backend
Demonstrate Workers Smart Placement by fetching an origin URL and reporting latency alongside the request colo. wrangler.json sets "placement": { "mode": "smart" } so Cloudflare can place the Worker closer to back-end origins based on traffic patterns.
API Reference
GET /
Explains Smart Placement and returns app metadata.
GET /probe
Fetch a URL and report status, latency, and colo.
url string (required)
http:// or https:// target.
Example Request
curl "https://your-worker.workers.dev/probe?url=https://example.com"Success Response
{
"url": "https://example.com/",
"status": 200,
"latencyMs": 42,
"cf": { "colo": "SJC" },
"workerPlacement": "Smart Placement may move this Worker closer to back-end origins based on request patterns."
}cf.colo comes from the incoming request.cf when available (empty object in local dev).
Error Codes
400- Missing or non-http(s) url (INVALID_URL)
Use Cases
- Learn Smart Placement configuration and behavior
- Measure origin latency from the serving colo
- Compare placement effects after repeated traffic to distant origins
- Debug whether a Worker is running near your back-end
Limitations
- Smart Placement effects are most visible after deploy with repeated traffic
- Single PoP / colo per request - not a multi-region map
cf.colomay be empty in localwrangler dev- No control plane API to force a specific colo
Use in your project
Copy these files into an existing Worker. Prefer Deployment to try the full experiment first. Source: apps/experiments/smart-placement-probe.
import { FETCH_TIMEOUT_MS, SMART_PLACEMENT_HINT } from "../constants/defaults";import type { ProbeResult } from "../types/probe";export async function probeUrl(url: string, colo?: string): Promise<ProbeResult> { const start = Date.now(); const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS); try { const res = await fetch(url, { method: "GET", signal: controller.signal, headers: { "User-Agent": "Cloudflare-Experiments-SmartPlacementProbe/1.0" }, }); clearTimeout(timeoutId); return { url, status: res.status, latencyMs: Date.now() - start, cf: colo ? { colo } : {}, workerPlacement: SMART_PLACEMENT_HINT, }; } catch (e) { clearTimeout(timeoutId); const message = e instanceof Error ? e.message : "Fetch failed"; return { url, status: 0, latencyMs: Date.now() - start, cf: colo ? { colo } : {}, workerPlacement: SMART_PLACEMENT_HINT, error: message, }; }}export function getRequestColo(request: Request): string | undefined { const cf = (request as Request & { cf?: { colo?: string } }).cf; return typeof cf?.colo === "string" ? cf.colo : undefined;}Deployment
Deploy
No extra bindings - placement.mode: "smart" is already set in wrangler.json.
Test your deployment
curl "https://your-worker.workers.dev/probe?url=https://example.com"Local Development
cd apps/experiments/smart-placement-probe
npm install
npm run devcurl "http://localhost:8787/probe?url=https://example.com"Smart Placement behavior is most visible after deploy with repeated requests to distant origins.
Cloudflare Features Used
- Workers - Edge compute runtime
- Smart Placement - Place Workers closer to back-end origins