cloudflare-development

Cloudflare Workers, Pages, KV, D1, R2, and Durable Objects development best practices for edge computing applications.

By mindrally · 642 installs

npx skills add mindrally/skills --skill cloudflare-development

Source repository · Upstream listing

Cloudflare Development Best Practices Overview This skill provides comprehensive guidelines for developing applications on Cloudflare's edge platform, including Workers, Pages, KV storage, D1 databases, R2 object storage, and Durable Objects. Core Principles Write lightweight, fast code optimized for edge execution Minimize cold start times and execution duration Use appropriate storage solutions for each use case Follow security best practices for edge computing Leverage Cloudflare's global network for performance Cloudflare Workers Guidelines Basic Worker Structure Environment Types Best Practices Use TypeScript for type safety Handle errors at the edge appropriately Implement proper request validation Use ctx.waitUntil() for background tasks Minimize external API calls when possible Wrangler Configuration wrangler.toml Structure KV Storage Guidelines Usage Patterns Best Practices Use KV for read heavy workloads with eventual consistency Set appropriate TTLs for cached data Use metadata for additional key information Implement cache invalidation strategies Be aware of KV's eventual consistency model D1 Database Guidelines Query Patterns Schema Management Best Practices Always use parameterized queries Create appropriate indexes Use batch operations for multiple writes Keep queries simple and efficient Use migrations for schema changes R2 Object Storage Guidelines Usage Patterns Best Practices Set appropriate content types Use multipart uploads for large files Implement proper access controls Use presigned URLs for direct client uploads Organize objects with logical prefixes Durable Objects Guidelines Implementation Best Practices Use for coordination and stateful logic Implement proper WebSocket handling Use storage API for persistence Handle hibernation for cost optimization Design for single point of coordination patterns Cloudflare Pages Guidelines Project Structure Pages Functions Edge Security Best Practices Request Validation Authentication Rate Limiting Performance Optimization Caching Strategies Background Processing Testing Local Development Unit Testing Deployment Production Deployment CI/CD Integration Common Pitfalls to Avoid 1. Not handling errors at the edge properly 2. Making too many external API calls 3. Ignoring Worker CPU and memory limits 4. Not using appropriate storage for use case 5. Forgetting eventual consistency in KV 6. Not implementing proper rate limiting 7. Hardcoding secrets in code 8. Ignoring cold start optimization