deployment
Cloudflare Configuration Guide
Overview
This cloudflare.toml
file provides comprehensive configuration settings for deploying the Jekyll website on Cloudflare Pages. It defines build processes, security headers, routing rules, and performance optimizations.
Build Configuration
Build Command
command = "jekyll build"
- Specifies the command to build the Jekyll site
- Generates static files in the
_site
directory
Publish Directory
publish = "_site"
- Defines the directory containing the generated static site
- Cloudflare Pages will serve files from this directory
Environment and Ruby Version
RUBY_VERSION = "3.1.2"
JEKYLL_ENV = "production"
- Sets the Ruby version for the build environment
- Configures Jekyll to run in production mode
- Ensures compatibility with project dependencies
Security Headers
Transport Security
Strict-Transport-Security = "max-age=31536000; includeSubDomains; preload"
- Enforces HTTPS connections
- Prevents downgrade attacks
- Includes subdomains in security policy
Content Security
Content-Security-Policy = "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'"
- Restricts content sources
- Allows inline scripts and styles
- Mitigates cross-site scripting (XSS) risks
Additional Security Headers
X-Content-Type-Options: nosniff
- Prevents MIME type sniffing
X-Frame-Options: DENY
- Blocks iframe embeddings
Referrer-Policy: strict-origin-when-cross-origin
- Controls referrer information
Routing and Redirects
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
- Implements client-side routing
- Ensures all routes are handled by
index.html
- Supports single-page application (SPA) behavior
Environment-Specific Builds
Production Deployment
[context.production]
command = "jekyll build"
- Standard build for production environment
Preview and Branch Deployments
[context.preview]
command = "jekyll build --drafts --future"
[context.branch-deploy]
command = "jekyll build --drafts --future"
- Builds site with drafts and future-dated posts
- Useful for previewing changes before merging
Performance Optimizations
Caching Strategies
[[headers]]
for = "*.css"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
- Implements aggressive caching for static assets
- Improves website performance
- Reduces server load and bandwidth usage
Cached file types:
- CSS files
- JavaScript files
- PNG images
- JPG images
- SVG graphics
Best Practices
- Regularly review and update security headers
- Ensure Ruby version matches project requirements
- Use environment-specific builds for different deployment contexts
- Monitor caching strategies for optimal performance