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/static-assets/gotchas.md
1## Best Practices23### 1. Use Selective Worker-First Routing45Instead of `run_worker_first = true`, use array patterns:67```jsonc8{9"assets": {10"run_worker_first": [11"/api/*", // API routes12"/admin/*", // Admin area13"!/admin/assets/*" // Except admin assets14]15}16}17```1819**Benefits:**20- Reduces Worker invocations21- Lowers costs22- Improves asset delivery performance2324### 2. Leverage Navigation Request Optimization2526For SPAs, use `compatibility_date = "2025-04-01"` or later:2728```jsonc29{30"compatibility_date": "2025-04-01",31"assets": {32"not_found_handling": "single-page-application"33}34}35```3637Navigation requests skip Worker invocation, reducing costs.3839### 3. Type Safety with Bindings4041Always type your environment:4243```typescript44interface Env {45ASSETS: Fetcher;46}47```4849## Common Errors5051### "Asset not found"5253**Cause:** Asset not in assets directory, wrong path, or assets not deployed54**Solution:** Verify asset exists, check path case-sensitivity, redeploy if needed5556### "Worker not invoked for asset"5758**Cause:** Asset served directly, `run_worker_first` not configured59**Solution:** Configure `run_worker_first` patterns to include asset routes (see configuration.md:66-106)6061### "429 Too Many Requests on free tier"6263**Cause:** `run_worker_first` patterns invoke Worker for many requests, hitting free tier limits (100k req/day)64**Solution:** Use more selective patterns with negative exclusions, or upgrade to paid plan6566### "Smart Placement increases latency"6768**Cause:** `run_worker_first=true` + Smart Placement routes all requests through single smart-placed location69**Solution:** Use selective patterns (array syntax) or disable Smart Placement for asset-heavy apps7071### "CF-Cache-Status header unreliable"7273**Cause:** Header is probabilistically added for privacy reasons74**Solution:** Don't rely on `CF-Cache-Status` for critical routing logic. Use other signals (ETag, age).7576### "JWT expired during deployment"7778**Cause:** Large asset deployments exceed JWT token lifetime79**Solution:** Update to Wrangler 4.34.0+ (automatic token refresh), or reduce asset count8081### "Cannot use 'assets' with 'site'"8283**Cause:** Legacy `site` config conflicts with new `assets` config84**Solution:** Migrate from `site` to `assets` (see configuration.md). Remove `site` key from wrangler.jsonc.8586### "Assets not updating after deployment"8788**Cause:** Browser or CDN cache serving old assets89**Solution:**90- Hard refresh browser (Cmd+Shift+R / Ctrl+F5)91- Use cache-busting (hashed filenames)92- Verify deployment completed: `wrangler tail`9394## Limits9596| Resource/Limit | Free | Paid | Notes |97|----------------|------|------|-------|98| Max asset size | 25 MiB | 25 MiB | Per file |99| Total assets | 20,000 | **100,000** | Requires Wrangler 4.34.0+ (Sep 2025) |100| Worker invocations | 100k/day | 10M/month | Optimize with `run_worker_first` patterns |101| Asset storage | Unlimited | Unlimited | Included |102103### Version Requirements104105| Feature | Minimum Wrangler Version |106|---------|--------------------------|107| 100k file limit (paid) | 4.34.0 |108| Vite plugin | 4.0.0 + @cloudflare/vite-plugin 1.0.0 |109| Navigation optimization | 4.0.0 + compatibility_date: "2025-04-01" |110111## Performance Tips112113### 1. Use Hashed Filenames114115Enable long-term caching with content-hashed filenames:116117```118app.a3b2c1d4.js119styles.e5f6g7h8.css120```121122Most bundlers (Vite, Webpack, Parcel) do this automatically.123124### 2. Minimize Worker Invocations125126Serve assets directly when possible:127128```jsonc129{130"assets": {131// Only invoke Worker for dynamic routes132"run_worker_first": ["/api/*", "/auth/*"]133}134}135```136137### 3. Leverage Browser Cache138139Set appropriate `Cache-Control` headers:140141```typescript142// Versioned assets143'Cache-Control': 'public, max-age=31536000, immutable'144145// HTML (revalidate often)146'Cache-Control': 'public, max-age=0, must-revalidate'147```148149See patterns.md:169-189 for implementation.150151### 4. Use .assetsignore152153Reduce upload time by excluding unnecessary files:154155```156*.map157*.md158.DS_Store159node_modules/160```161162See configuration.md:107-126 for details.163