Google Antigravity Directory

The #1 directory for Google Antigravity prompts, rules, workflows & MCP servers. Optimized for Gemini 3 agentic development.

Resources

PromptsMCP ServersAntigravity RulesGEMINI.md GuideBest Practices

Company

Submit PromptAntigravityAI.directory

Popular Prompts

Next.js 14 App RouterReact TypeScriptTypeScript AdvancedFastAPI GuideDocker Best Practices

Legal

Privacy PolicyTerms of ServiceContact Us
Featured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver ToolsFeatured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver Tools

© 2026 Antigravity AI Directory. All rights reserved.

The #1 directory for Google Antigravity IDE

This website is not affiliated with, endorsed by, or associated with Google LLC. "Google" and "Gemini" are trademarks of Google LLC.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
Cloudflare Edge Optimization

Cloudflare Edge Optimization

Optimize Google Antigravity applications with Cloudflare including edge caching, Workers, R2 storage, and security features.

cloudflareedgecachingcdnperformance
by antigravity-team
⭐0Stars
.antigravity
# Cloudflare Edge Optimization

Optimize your Google Antigravity applications with Cloudflare edge services. This guide covers caching strategies, Workers, R2 storage, and security configurations.

## Cloudflare Configuration

Set up optimal Cloudflare settings:

```typescript
// cloudflare/page-rules.ts
// Configure via Cloudflare Dashboard or API

const pageRules = [
  {
    target: "*antigravityai.directory/_next/static/*",
    actions: {
      cacheLevel: "cacheEverything",
      edgeCacheTTL: 31536000, // 1 year
      browserCacheTTL: 31536000,
    },
  },
  {
    target: "*antigravityai.directory/api/*",
    actions: {
      cacheLevel: "bypass",
      securityLevel: "high",
    },
  },
  {
    target: "*antigravityai.directory/*",
    actions: {
      cacheLevel: "standard",
      edgeCacheTTL: 7200, // 2 hours
      browserCacheTTL: 3600, // 1 hour
      minify: {
        javascript: true,
        css: true,
        html: true,
      },
    },
  },
];
```

## Cloudflare Worker for Edge Logic

Implement edge logic with Workers:

```typescript
// workers/edge-handler.ts
export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const url = new URL(request.url);

    // A/B testing at the edge
    if (url.pathname === "/" || url.pathname === "/prompts") {
      const cookie = request.headers.get("cookie") || "";
      const variant = cookie.includes("ab_variant=")
        ? cookie.match(/ab_variant=(\w+)/)?.[1]
        : Math.random() > 0.5 ? "a" : "b";

      const response = await fetch(request);
      const newResponse = new Response(response.body, response);

      if (!cookie.includes("ab_variant=")) {
        newResponse.headers.set(
          "Set-Cookie",
          `ab_variant=${variant}; Path=/; Max-Age=604800`
        );
      }

      newResponse.headers.set("X-AB-Variant", variant);
      return newResponse;
    }

    // Geolocation-based routing
    const country = request.cf?.country || "US";
    if (url.pathname.startsWith("/api/") && ["CN", "RU"].includes(country)) {
      return new Response("Access denied", { status: 403 });
    }

    // Rate limiting
    const clientIP = request.headers.get("CF-Connecting-IP") || "";
    const rateLimitKey = `rate:${clientIP}`;
    const requests = await env.KV.get(rateLimitKey);
    const count = parseInt(requests || "0", 10);

    if (count > 100) {
      return new Response("Rate limit exceeded", { status: 429 });
    }

    await env.KV.put(rateLimitKey, String(count + 1), { expirationTtl: 60 });

    return fetch(request);
  },
};
```

## R2 Storage Integration

Use R2 for edge-optimized storage:

```typescript
// lib/cloudflare/r2-client.ts
import { S3Client, PutObjectCommand, GetObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";

// R2 is S3-compatible
const r2Client = new S3Client({
  region: "auto",
  endpoint: `https://${process.env.CF_ACCOUNT_ID}.r2.cloudflarestorage.com`,
  credentials: {
    accessKeyId: process.env.R2_ACCESS_KEY_ID!,
    secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,
  },
});

export async function uploadToR2(
  key: string,
  body: Buffer | ReadableStream,
  contentType: string
): Promise<string> {
  await r2Client.send(
    new PutObjectCommand({
      Bucket: process.env.R2_BUCKET_NAME!,
      Key: key,
      Body: body,
      ContentType: contentType,
    })
  );

  // Return public URL via Cloudflare CDN
  return `https://cdn.antigravityai.directory/${key}`;
}

export async function getSignedR2Url(key: string): Promise<string> {
  const command = new GetObjectCommand({
    Bucket: process.env.R2_BUCKET_NAME!,
    Key: key,
  });

  return getSignedUrl(r2Client, command, { expiresIn: 3600 });
}
```

## Cache Headers in Next.js

Optimize caching from your application:

```typescript
// next.config.ts
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  async headers() {
    return [
      {
        source: "/_next/static/:path*",
        headers: [
          {
            key: "Cache-Control",
            value: "public, max-age=31536000, immutable",
          },
          {
            key: "CDN-Cache-Control",
            value: "public, max-age=31536000, immutable",
          },
        ],
      },
      {
        source: "/api/:path*",
        headers: [
          {
            key: "Cache-Control",
            value: "no-store, must-revalidate",
          },
          {
            key: "CDN-Cache-Control",
            value: "no-store",
          },
        ],
      },
      {
        source: "/:path*",
        headers: [
          {
            key: "Cache-Control",
            value: "public, max-age=0, s-maxage=86400, stale-while-revalidate=86400",
          },
        ],
      },
    ];
  },
};

export default nextConfig;
```

## Security Configuration

Harden security at the edge:

```typescript
// Cloudflare security settings
const securitySettings = {
  // WAF Rules
  waf: {
    enabled: true,
    mode: "block",
    rules: [
      "OWASP Core Ruleset",
      "Cloudflare Managed Ruleset",
    ],
  },
  // Bot Management
  botManagement: {
    enabled: true,
    blockAI: false,
    challengeBots: true,
  },
  // DDoS Protection
  ddos: {
    sensitivityLevel: "medium",
    rulesets: ["HTTP DDoS Attack Protection"],
  },
};
```

## Best Practices

1. **Cache Static Assets**: Set long TTLs for immutable static files
2. **Edge Caching**: Use CDN-Cache-Control for fine-grained control
3. **R2 for Assets**: Use R2 for user uploads with CDN delivery
4. **Workers for Logic**: Implement edge logic without origin roundtrips
5. **Security Headers**: Configure WAF and bot protection
6. **Analytics**: Monitor cache hit ratios and performance

When to Use This Prompt

This cloudflare prompt is ideal for developers working on:

  • cloudflare applications requiring modern best practices and optimal performance
  • Projects that need production-ready cloudflare code with proper error handling
  • Teams looking to standardize their cloudflare development workflow
  • Developers wanting to learn industry-standard cloudflare patterns and techniques

By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their cloudflare implementations.

How to Use

  1. Copy the prompt - Click the copy button above to copy the entire prompt to your clipboard
  2. Paste into your AI assistant - Use with Claude, ChatGPT, Cursor, or any AI coding tool
  3. Customize as needed - Adjust the prompt based on your specific requirements
  4. Review the output - Always review generated code for security and correctness
💡 Pro Tip: For best results, provide context about your project structure and any specific constraints or preferences you have.

Best Practices

  • ✓ Always review generated code for security vulnerabilities before deploying
  • ✓ Test the cloudflare code in a development environment first
  • ✓ Customize the prompt output to match your project's coding standards
  • ✓ Keep your AI assistant's context window in mind for complex requirements
  • ✓ Version control your prompts alongside your code for reproducibility

Frequently Asked Questions

Can I use this cloudflare prompt commercially?

Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.

Which AI assistants work best with this prompt?

This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.

How do I customize this prompt for my specific needs?

You can modify the prompt by adding specific requirements, constraints, or preferences. For cloudflare projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...