Prerequisites
Before deploying to Cloudflare Pages:- A Cloudflare account (sign up at cloudflare.com)
- A Cloudflare API token with Pages permissions
- A completed build ready for deployment
Authentication Setup
Cloudflare Pages requires an API token for authentication.Create an API token
- Go to Cloudflare Dashboard > My Profile > API Tokens
- Click “Create Token”
- Use the “Edit Cloudflare Workers” template or create a custom token
- Ensure it has these permissions:
- Account > Cloudflare Pages > Edit
- Copy the generated token
Destination Configuration
Configure your Cloudflare Pages deployment destination:Configuration Fields
- accountName (required): Your Cloudflare account name
- Displayed in the Cloudflare dashboard
- Used to auto-resolve account ID
- accountId (auto-resolved): Automatically resolved from account name
- projectName (required): Your Pages project name
- Must be unique within your account
- Used in the default URL
The account ID is automatically resolved from your account name during validation.
Deployment Process
Select account and project
Configure your deployment:
- Choose your Cloudflare account by name
- Specify a project name
- Project will be created if it doesn’t exist
Build your site
Complete a build in Opal Editor:
- Source files are processed
- Static HTML is generated
- Assets are prepared
- Files are ready for upload
Deploy to Cloudflare Pages
Start deployment:
- Files are uploaded to Cloudflare Pages
- Project is created if needed
- Deployment is processed on Cloudflare’s network
- Progress is tracked in real-time
How It Works
The Cloudflare deployment agent (RemoteAuthCloudflareAPIAgent) handles:- Account Resolution: Validates account name and resolves account ID
- Project Management: Creates project if it doesn’t exist
- File Upload: Converts and uploads files to Cloudflare Pages
- Deployment Tracking: Monitors deployment status
- URL Generation: Returns both main and deployment-specific URLs
File Preparation
Opal Editor prepares files for Cloudflare Pages:- Text files (HTML, CSS, JS): UTF-8 encoding
- Binary files (images, fonts): Base64 encoding
- All file types supported
Features
Global CDN
Cloudflare’s massive global network:- 300+ data centers worldwide
- Content served from nearest location
- Automatic edge caching
- DDoS protection included
Unlimited Bandwidth
Cloudflare Pages includes:- Unlimited bandwidth on all plans
- No usage limits
- Free for static sites
Automatic HTTPS
Security by default:- Automatic SSL certificates
- HTTPS enforced
- Modern TLS versions
- No configuration needed
Web Analytics
Free analytics included:- Page views and visits
- Geographic distribution
- Referrer tracking
- No impact on performance
Account Management
Cloudflare supports multiple accounts:- Personal accounts
- Organization accounts
- Multiple projects per account
- Fetches all accessible accounts
- Resolves account ID from name
- Lists projects within selected account
Troubleshooting
Account Not Found
Solution: Copy the exact account name from your Cloudflare Dashboard.Permission Errors
If you see permission errors:- Verify API token has Cloudflare Pages Edit permissions
- Check token hasn’t expired
- Ensure token is scoped to the correct account
- Try creating a new token with appropriate permissions
Deployment Failures
If deployment fails:- Check deployment logs for specific errors
- Verify your build completed successfully
- Ensure all files are valid
- Check Cloudflare’s status page for outages
Project Creation Issues
If project creation fails:- Verify project name is unique in your account
- Check name follows Cloudflare’s naming rules
- Ensure you have available project slots
- Try a different project name
Best Practices
- Use descriptive project names: Choose meaningful names for easy identification
- Monitor deployments: Watch logs for warnings or errors
- Test before deploying: Ensure builds complete successfully locally
- Configure custom domains: Set up custom domains in Cloudflare dashboard
- Enable analytics: Use Cloudflare’s free Web Analytics for insights
- Set up redirects: Configure redirects and headers for optimal performance
Advanced Configuration
Custom Domains
Add custom domains in the Cloudflare dashboard:- Navigate to your Pages project
- Go to Custom domains tab
- Add your domain
- Cloudflare handles DNS automatically if domain is on Cloudflare
Headers and Redirects
Configure custom headers and redirects: Create a_headers file:
_redirects file:
Build Configuration
Include awrangler.toml for advanced configuration:
Edge Functions
While Opal Editor deploys static files, you can add edge functions:- Create
functionsdirectory in your build - Add JavaScript/TypeScript files
- Deploy alongside static content
- Functions run on Cloudflare’s edge network
Performance Optimization
Caching
Cloudflare automatically caches:- Static assets (images, CSS, JS)
- HTML with appropriate cache headers
- Configurable cache rules
Compression
Automatic compression:- Brotli compression for modern browsers
- Gzip fallback for older browsers
- No configuration required
HTTP/3
Modern protocol support:- HTTP/3 enabled by default
- QUIC protocol for faster connections
- Automatic fallback to HTTP/2