Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/smart-placement/gotchas.md
1# Smart Placement Gotchas23## Common Errors45### "INSUFFICIENT_INVOCATIONS"67**Cause:** Not enough traffic for Smart Placement to analyze8**Solution:**9- Ensure Worker receives consistent global traffic10- Wait longer (analysis takes up to 15 minutes)11- Send test traffic from multiple global locations12- Check Worker has fetch event handler1314### "UNSUPPORTED_APPLICATION"1516**Cause:** Smart Placement made Worker slower rather than faster17**Reasons:**18- Worker doesn't make backend calls (runs faster at edge)19- Backend calls are cached (network latency to user more important)20- Backend service has good global distribution21- Worker serves static assets or Pages content2223**Solutions:**24- Disable Smart Placement: `{ "placement": { "mode": "off" } }`25- Review whether Worker actually benefits from Smart Placement26- Consider caching strategy to reduce backend calls27- For Pages/Assets Workers, use separate backend Worker with Smart Placement2829### "No request duration metrics"3031**Cause:** Smart Placement not enabled, insufficient time passed, insufficient traffic, or analysis incomplete32**Solution:**33- Ensure Smart Placement enabled in config34- Wait 15+ minutes after deployment35- Verify Worker has sufficient traffic36- Check `placement_status` is `SUCCESS`3738### "cf-placement header missing"3940**Cause:** Smart Placement not enabled, beta feature removed, or Worker not analyzed yet41**Solution:** Verify Smart Placement enabled, wait for analysis (15min), check if beta feature still available4243## Pages/Assets + Smart Placement Performance Degradation4445**Problem:** Static assets load 2-5x slower when Smart Placement enabled with `run_worker_first = true`.4647**Cause:** Smart Placement routes ALL requests (including static assets like HTML, CSS, JS, images) to remote locations. Static content should ALWAYS be served from edge closest to user.4849**Solution:** Split into separate Workers OR disable Smart Placement:50```jsonc51// ❌ BAD - Assets routed away from user52{53"name": "pages-app",54"placement": { "mode": "smart" },55"assets": { "run_worker_first": true }56}5758// ✅ GOOD - Assets at edge, API optimized59// frontend/wrangler.jsonc60{61"name": "frontend",62"assets": { "run_worker_first": true }63// No placement field - stays at edge64}6566// backend/wrangler.jsonc67{68"name": "backend-api",69"placement": { "mode": "smart" }70}71```7273This is one of the most common and impactful Smart Placement misconfigurations.7475## Monolithic Full-Stack Worker7677**Problem:** Frontend and backend logic in single Worker with Smart Placement enabled.7879**Cause:** Smart Placement optimizes for backend latency but increases user-facing response time.8081**Solution:** Split into two Workers:82```jsonc83// frontend/wrangler.jsonc84{85"name": "frontend",86"placement": { "mode": "off" }, // Explicit: stay at edge87"services": [{ "binding": "BACKEND", "service": "backend-api" }]88}8990// backend/wrangler.jsonc91{92"name": "backend-api",93"placement": { "mode": "smart" },94"d1_databases": [{ "binding": "DB", "database_id": "xxx" }]95}96```9798## Local Development Confusion99100**Issue:** Smart Placement doesn't work in `wrangler dev`.101102**Explanation:** Smart Placement only activates in production deployments, not local development.103104**Solution:** Test Smart Placement in staging environment: `wrangler deploy --env staging`105106## Baseline Traffic & Analysis Time107108**Note:** Smart Placement routes 1% of requests WITHOUT optimization for comparison (expected).109110**Analysis time:** Up to 15 minutes. During analysis, Worker runs at edge. Monitor `placement_status`.111112## RPC Methods Not Affected (Critical Limitation)113114**Problem:** Enabled Smart Placement on backend but RPC calls still slow.115116**Cause:** Smart Placement ONLY affects `fetch` handlers. RPC methods (Service Bindings with `WorkerEntrypoint`) are NEVER affected.117118**Why:** RPC bypasses `fetch` handler - Smart Placement can only route `fetch` requests.119120**Solution:** Convert to fetch-based Service Bindings:121122```typescript123// ❌ RPC - Smart Placement has NO EFFECT124export class BackendRPC extends WorkerEntrypoint {125async getData() {126// ALWAYS runs at edge127return await this.env.DATABASE.prepare('SELECT * FROM table').all();128}129}130131// ✅ Fetch - Smart Placement WORKS132export default {133async fetch(request: Request, env: Env): Promise<Response> {134// Runs close to DATABASE when Smart Placement enabled135const data = await env.DATABASE.prepare('SELECT * FROM table').all();136return Response.json(data);137}138}139```140141## Requirements142143- **Wrangler 2.20.0+** required144- **Consistent multi-region traffic** needed for analysis145- **Only affects fetch handlers** - RPC methods and named entrypoints not affected146147## Limits148149| Resource/Limit | Value | Notes |150|----------------|-------|-------|151| Analysis time | Up to 15 minutes | After enabling |152| Baseline traffic | 1% | Routed without optimization |153| Min Wrangler version | 2.20.0+ | Required |154| Traffic requirement | Multi-region | Consistent needed |155156## Disabling Smart Placement157158```jsonc159{ "placement": { "mode": "off" } } // Explicit disable160// OR remove "placement" field entirely (same effect)161```162163Both behaviors identical - Worker runs at edge closest to user.164165## When NOT to Use Smart Placement166167- Workers serving only static content or cached responses168- Workers without significant backend communication169- Pure edge logic (auth checks, redirects, simple transformations)170- Workers without fetch event handlers171- Pages/Assets Workers with `run_worker_first = true`172- Workers using RPC methods instead of fetch handlers173174These scenarios won't benefit and may perform worse with Smart Placement.175