| | |

GitHub Pages 12 ๐Ÿ“„ Extending Pages with Cloudflare & Edge Proxies โ€” Adding custom HTTP headers, 301 redirects, Brotli compression, and edge caching

โฑ๏ธ Estimated read: 16 min | |

GitHub Pages is an exceptional, zero-cost static hosting platform, but its baseline infrastructure lacks several enterprise-level web capabilities. Out of the box, GitHub Pages does not support custom HTTP response headers (such as Content-Security-Policy, Strict-Transport-Security, or custom CORS headers), server-side HTTP 301/302 redirects, or fine-grained browser caching controls. Additionally, while GitHub Pages serves files with default Gzip encoding, it does not provide native Brotli compression or customizable edge-caching policies across global Points of Presence (PoPs).

To bridge these capability gaps without abandoning the simplicity of static site deployment on GitHub, developers deploy reverse proxies and edge computing layersโ€”most notably Cloudflareโ€”in front of their GitHub Pages origin server. By pointing your domain’s DNS CNAME records to pass through an edge network proxy, incoming HTTP requests can be dynamically modified, cached, redirected, and augmented with enterprise security headers before reaching or returning from the origin.

This chapter demonstrates how to extend GitHub Pages using Cloudflare Workers, Page Rules, Response Header Transform Rules, and Edge Cache Rules. We will examine how to add critical security headers, construct edge-based 301 redirects to preserve SEO ranking, force modern Brotli compression, and tune Tiered Cache settings. The sections that follow walk through setting up custom HTTP headers via Cloudflare Transform Rules, implementing edge-based URL rewrites and redirects with Cloudflare Workers, and configuring advanced caching strategies.

Key point: GitHub Pages acts as an immutable static origin; by placing an edge proxy like Cloudflare in front of it, you can dynamically inject security headers, execute true HTTP 301 redirects, force Brotli compression, and override cache TTLs without touching your origin codebase.


Why exists

The security header gap. Modern web browsers rely on HTTP response headers like Content-Security-Policy (CSP), Strict-Transport-Security (HSTS), and X-Frame-Options to mitigate cross-site scripting (XSS), clickjacking, and protocol downgrade attacks. GitHub Pages serves static files with fixed, minimal headers that cannot be customized via .htaccess, _headers, or repository configuration files.

The SEO redirect limitation. When restructuring a static website hosted on GitHub Pages, developers often resort to HTML <meta http-equiv="refresh"> tags or client-side JavaScript redirects. Search engines treat client-side refreshes differently than true HTTP 301 Moved Permanently headers, resulting in lost backlink authority and degraded indexing performance.

The rigid cache control constraint. GitHub Pages hardcodes its response header Cache-Control: max-age=600 (10 minutes) for custom domains. For high-traffic static assets like fonts, immutable images, and historical documentation, 10 minutes is inefficiently low, causing unnecessary traffic to return to the origin and slowing down global load times.

The compression bottleneck. While GitHub Pages supports standard Gzip compression, it does not support Brotli compression for custom asset types. Brotli offers a 15โ€“25% smaller payload size compared to Gzip for text assets (HTML, CSS, JavaScript), directly impacting Core Web Vitals such as Largest Contentful Paint (LCP).

The origin rate-limiting trade-off. GitHub Pages enforces soft bandwidth and request limits (100 GB traffic per month, 100 builds per hour). Placing a global edge proxy in front of the origin offloads over 95% of requests to edge caches, protecting your site from traffic surges and origin denial-of-service scenarios.


a. Adding Custom HTTP Headers and Edge Rules

Because GitHub Pages does not allow direct configuration of the underlying Nginx/web server layer, headers must be injected while the HTTP response passes through the edge proxy network. Cloudflare provides two main approaches for this: declarative Response Header Transform Rules (managed via the Cloudflare dashboard or API) and programmatic Cloudflare Workers (JavaScript executing on V8 at the edge).

Response Header Transform Rules allow you to add, modify, or remove HTTP response headers without writing code. This is ideal for static security policies where every HTML or asset response requires standard defense headers.

// Cloudflare Worker script for injecting comprehensive security headers
// Filename: worker-security-headers.js

// Define the security headers matrix to append to all origin responses
const SECURITY_HEADERS = {
  "Content-Security-Policy": "default-src 'self'; script-src 'self' 'unsafe-inline' https://cdnjs.cloudflare.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:;", // Prevents unauthorized script execution
  "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", // Forces HTTPS for 1 year including subdomains
  "X-Frame-Options": "DENY", // Completely blocks framing to eliminate clickjacking risks
  "X-Content-Type-Options": "nosniff", // Forces browser to strictly respect declared MIME types
  "Referrer-Policy": "strict-origin-when-cross-origin", // Restricts referrer information sent with outbound links
  "Permissions-Policy": "geolocation=(), microphone=(), camera=()", // Disables access to sensitive hardware APIs
  "X-XSS-Protection": "0" // Disables obsolete legacy browser XSS filters in favor of CSP
};

export default {
  async fetch(request, env, ctx) {
    // Fetch the raw response from the upstream GitHub Pages origin server
    const response = await fetch(request);

    // Create a mutable copy of the response headers
    const newHeaders = new Headers(response.headers);

    // Iterate through defined security headers and append/override them
    Object.entries(SECURITY_HEADERS).forEach(([header, value]) => {
      newHeaders.set(header, value); // Inject header into edge response stream
    });

    // Remove headers exposed by default origin that reveal server implementation details
    newHeaders.delete("Server"); // Conceals Nginx version
    newHeaders.delete("X-GitHub-Request-Id"); // Removes internal GitHub tracing identifiers

    // Return the augmented response object back to the requesting client
    return new Response(response.body, {
      status: response.status, // Preserve original HTTP status code (e.g., 200, 404)
      statusText: response.statusText, // Preserve original status text
      headers: newHeaders // Supply updated header map containing security rules
    });
  }
};

When implementing the Worker code above, every request arriving at Cloudflare is forwarded to GitHub Pages (https://username.github.io/repository/), the original headers are intercepted, and the enhanced security suite is injected before the response hits the user’s browser. This process adds negligible latency (typically under 2 milliseconds) because V8 isolate contexts start instantly at the edge location nearest to the client.


b. Managing 301/302 Redirects at the Edge

A major operational challenge with static sites on GitHub Pages is handling structural URL updates. If you rename /old-path.html to /new-path/, GitHub Pages returns a 404 Not Found error. Creating client-side HTML redirects using <meta http-equiv="refresh"> forces an extra network round-trip and fails to communicate permanent relocation to search engine crawlers.

Edge proxies allow developers to execute high-performance 301 (Permanent) and 302 (Temporary) HTTP redirects at the network layer. The request never hits the GitHub Pages origin, saving bandwidth and delivering response times under 10ms.

// Cloudflare Worker script for path mapping and canonical URL enforcement
// Filename: worker-redirects.js

// Hardcoded map of legacy static routes to new permalinks
const REDIRECT_MAP = new Map([
  ["/docs/v1/install", "/docs/installation"], // Maps legacy v1 docs path to unified path
  ["/blog/2021/hello-world", "/posts/hello-world"], // Maps old blog structural path
  ["/twitter", "https://twitter.com/myproject"], // External social media alias redirect
  ["/discord", "https://discord.gg/example"] // External community alias redirect
]);

export default {
  async fetch(request, env, ctx) {
    const url = new URL(request.url); // Parse incoming HTTP request URL string
    const pathname = url.pathname.toLowerCase(); // Standardize path string to lowercase

    // 1. Check for exact match within the static URL redirect map
    if (REDIRECT_MAP.has(pathname)) {
      const destination = REDIRECT_MAP.get(pathname); // Extract target URL destination
      return Response.redirect(destination, 301); // Issue immediate 301 Moved Permanently
    }

    // 2. Enforce Canonical Hostname (e.g., strip 'www.' prefix to standardize domain)
    if (url.hostname.startsWith("www.")) {
      url.hostname = url.hostname.replace("www.", ""); // Remove www subdomain
      return Response.redirect(url.toString(), 301); // Issue 301 redirect to apex domain
    }

    // 3. Remove trailing slashes on non-root paths for unified canonical URLs
    if (pathname.length > 1 && pathname.endsWith("/")) {
      url.pathname = url.pathname.slice(0, -1); // Trim final trailing slash character
      return Response.redirect(url.toString(), 301); // Issue 301 redirect to non-slash path
    }

    // If no redirect condition matches, forward request to GitHub Pages origin
    return await fetch(request);
  }
};

By processing these rules directly inside Cloudflare Workers or Cloudflare Dynamic Redirect Rules, URL adjustments, canonical domain normalization (enforcing HTTPS and non-WWW), and path migration execute entirely in memory across more than 300 global data centers.


c. Brotli Compression and Edge Caching Strategies

GitHub Pages origin servers serve content with default Cache-Control: max-age=600 directives and standard Gzip compression. When integrating Cloudflare, you can override these defaults by configuring Cloudflare Cache Rules and automatic compression settings.

Brotli compression utilizes a modern dictionary-based algorithm that achieves significantly higher compression ratios than Gzip for web assets:

  • HTML files: 15% to 25% smaller than Gzip.
  • CSS stylesheets: 15% to 20% smaller than Gzip.
  • JavaScript bundles: 10% to 15% smaller than Gzip.

Because Cloudflare can re-compress responses on the fly or pull pre-compressed content, enabling Brotli at the edgeproxy level immediately optimizes your site’s network payload without requiring changes to your GitHub Actions build pipeline.

// Cloudflare Worker for overriding GitHub Pages default cache policies
// Filename: worker-cache-control.js

export default {
  async fetch(request, env, ctx) {
    const response = await fetch(request, {
      cf: {
        // Force Cloudflare edge cache to hold static assets longer than origin requests
        cacheEverything: true, // Force caching of HTML files along with static assets
        cacheTtlByStatus: {
          "200-299": 2592000, // Cache successful responses for 30 days (2,592,000 seconds)
          "404": 60, // Cache 404 responses for only 60 seconds to allow rapid fixes
          "500-599": 0 // Do not cache origin server errors
        }
      }
    });

    const url = new URL(request.url);
    const newHeaders = new Headers(response.headers);

    // Apply strict immutability headers to hashed static assets (fonts, images, bundles)
    if (url.pathname.match(/\.(png|jpg|jpeg|webp|svg|woff2|ttf|css|js)$/)) {
      newHeaders.set(
        "Cache-Control",
        "public, max-age=31536000, immutable" // Instruct browser to cache asset for 1 full year
      );
    } else {
      // For HTML pages, set a balanced browser revalidation policy
      newHeaders.set(
        "Cache-Control",
        "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400" // Browser 1h, Edge 24h
      );
    }

    return new Response(response.body, {
      status: response.status,
      statusText: response.statusText,
      headers: newHeaders
    });
  }
};

This caching layer shifts your static site’s architecture into a true multi-tiered caching pipeline:

  1. Browser Cache: Assets with content hashes stay resident in local client storage (max-age=31536000).
  2. Edge Cache (Cloudflare PoPs): HTML pages and updated assets are cached globally (s-maxage=86400), shielding the GitHub origin.
  3. Origin (GitHub Pages): Receives less than 2โ€“5% of total request traffic, completely eliminating origin rate-limiting vulnerabilities.

Complete Example Session

// ============================================
// PART 1: DEFINING SECURITY HEADERS MATRIX
// ============================================
const SECURITY_POLICIES: Record<string, string> = {
  "Content-Security-Policy": "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:;", // Primary XSS mitigation policy
  "Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload", // Enforces HSTS for entire domain ecosystem
  "X-Frame-Options": "DENY", // Prevents clickjacking by blocking embedding inside iframes
  "X-Content-Type-Options": "nosniff", // Disables browser MIME-type guessing capabilities
  "Referrer-Policy": "strict-origin-when-cross-origin", // Sanitizes cross-origin request headers
  "Permissions-Policy": "camera=(), microphone=(), geolocation=()" // Disables unused browser device features
};

// ============================================
// PART 2: CLOUDFLARE WORKER ENTRY POINT
// ============================================
export default {
  async fetch(request: Request, env: unknown, ctx: { waitUntil: (p: Promise<unknown>) => void }): Promise<Response> {
    const url = new URL(request.url); // Extract URL instance from standard request

// ============================================
// PART 3: CANONICAL HOSTNAME & PROTOCOL ENFORCEMENT
// ============================================
    if (url.hostname.startsWith("www.")) {
      url.hostname = url.hostname.replace("www.", ""); // Strip www prefix
      return Response.redirect(url.toString(), 301); // Return 301 permanent redirect
    }

// ============================================
// PART 4: 301 ROUTE MAPPING DICTIONARY
// ============================================
    const redirectRoutes: Record<string, string> = {
      "/old-readme": "/docs/getting-started", // Map old project documentation root
      "/v1-api": "/api/v2-reference", // Map deprecated API endpoint URL
      "/releases": "https://github.com/myorg/myrepo/releases" // External redirect to GitHub Releases
    };

    if (redirectRoutes[url.pathname]) {
      return Response.redirect(redirectRoutes[url.pathname], 301); // Intercept and redirect immediately
    }

// ============================================
// PART 5: ORIGIN FETCH WITH EDGE CACHE OVERRIDES
// ============================================
    const originResponse = await fetch(request, {
      cf: {
        cacheEverything: true, // Force Cloudflare to cache HTML pages along with assets
        cacheTtl: 86400 // Set default edge TTL duration to 24 hours (86,400 seconds)
      }
    });

// ============================================
// PART 6: MUTABLE RESPONSE HEADER PREPARATION
// ============================================
    const modifiedHeaders = new Headers(originResponse.headers); // Copy immutable response headers

    Object.entries(SECURITY_POLICIES).forEach(([name, value]) => {
      modifiedHeaders.set(name, value); // Bulk inject security header policy map
    });

// ============================================
// PART 7: CUSTOM CACHE-CONTROL OVERRIDE LOGIC
// ============================================
    if (url.pathname.startsWith("/assets/") || url.pathname.match(/\.(woff2|css|js|png)$/)) {
      modifiedHeaders.set("Cache-Control", "public, max-age=31536000, immutable"); // 1 year immutable TTL
    } else {
      modifiedHeaders.set("Cache-Control", "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400"); // Dynamic HTML strategy
    }

// ============================================
// PART 8: REMOVE SERVER ACCIDENTALLY EXPOSED HEADERS
// ============================================
    modifiedHeaders.delete("Server"); // Remove origin server type disclosure
    modifiedHeaders.delete("X-GitHub-Request-Id"); // Strip internal GitHub infrastructure header

// ============================================
// PART 9: 404 CUSTOM ERROR HANDLING AT THE EDGE
// ============================================
    if (originResponse.status === 404) {
      modifiedHeaders.set("Cache-Control", "public, max-age=60"); // Restrict 404 caching to 60 seconds
    }

// ============================================
// PART 10: COMPLETE ASSEMBLY AND RESPONSE EMISSION
// ============================================
    return new Response(originResponse.body, {
      status: originResponse.status, // Preserve underlying response code
      statusText: originResponse.statusText, // Preserve status message text
      headers: modifiedHeaders // Inject updated headers containing edge rules
    });
  }
};

The ten-part script above defines a complete production Cloudflare Worker script that standardizes URLs, executes 301 redirects, proxies static content from GitHub Pages, injects enterprise security headers, customizes cache control policies, and strips origin information headers at the global edge.


Quick Reference

Recommended Security Headers Matrix

HeaderProduction Recommended ValuePurpose
Content-Security-Policydefault-src 'self'; script-src 'self'; style-src 'self'Prevents unauthorized cross-site scripts
Strict-Transport-Securitymax-age=31536000; includeSubDomains; preloadForces client browser HTTPS connections
X-Frame-OptionsDENY or SAMEORIGINBlocks framing to eliminate clickjacking
X-Content-Type-OptionsnosniffPrevents browser MIME-type sniffing
Referrer-Policystrict-origin-when-cross-originProtects sensitive URL path parameters
Permissions-Policygeolocation=(), camera=(), microphone=()Disables access to client hardware capabilities

Cache Control Strategies for GitHub Pages Edge Proxy

Target Asset TypeProposed Cache-Control ValueEdge TTLBrowser TTL
Hashed JS / CSSpublic, max-age=31536000, immutable1 Year1 Year
Web Fonts (.woff2)public, max-age=31536000, immutable1 Year1 Year
HTML Documentspublic, max-age=3600, s-maxage=8640024 Hours1 Hour
JSON / RSS Feedspublic, max-age=300, s-maxage=36001 Hour5 Minutes
404 Error Pagespublic, max-age=6060 Seconds60 Seconds

Cloudflare Proxy DNS Configuration

Record TypeName / HostTarget ValueProxy Status
CNAME@ (Apex)username.github.ioProxied (Orange Cloud)
CNAMEwwwusername.github.ioProxied (Orange Cloud)
TXT_github-pages-challengeVerification tokenDNS Only (Grey Cloud)

Best Practices

โœ… Do This:

// Enable Orange-Cloud proxying on Cloudflare CNAME to route traffic through the edge proxy
// DNS Configuration: CNAME @ -> username.github.io (Proxied = Enabled)       // โœ…

// Always preserve original response status code when proxying from origin
return new Response(response.body, { status: response.status, headers });    // โœ…

// Set 'immutable' on static assets containing hashed content filenames
headers.set("Cache-Control", "public, max-age=31536000, immutable");         // โœ…

// Strip internal origin headers to prevent server disclosure
headers.delete("X-GitHub-Request-Id");                                      // โœ…

// Perform 301 redirects at the edge prior to fetching content from origin
if (redirects[path]) return Response.redirect(redirects[path], 301);       // โœ…

// Set low edge cache TTL for 404 responses to avoid caching missing pages long-term
if (res.status === 404) headers.set("Cache-Control", "public, max-age=60");  // โœ…

โŒ Don’t Do This:

// Don't leave DNS records set to 'DNS Only' (Grey Cloud) when using Workers
// DNS Configuration: CNAME @ -> username.github.io (Proxied = Disabled)      // โŒ

// Don't hardcode a 200 status code when returning intercepted responses
return new Response(response.body, { status: 200, headers });                // โŒ

// Don't use meta refreshes in HTML for permanent page migration
// <meta http-equiv="refresh" content="0; url=/new-page">                    // โŒ

// Don't cache HTML responses immutably (users will never see layout updates)
headers.set("Cache-Control", "public, max-age=31536000, immutable"); // HTML  // โŒ

// Don't proxy traffic without defining a Content-Security-Policy header
// Missing CSP exposes static site users to third-party script injection     // โŒ

// Don't forget to pass original response headers when building Worker response
return new Response(response.body); // Leaves out all security rules          // โŒ

Common Pitfalls

PitfallWhy It HappensFix
Infinite Redirect LoopCloudflare SSL mode set to “Flexible” while GitHub Pages forces HTTPSChange Cloudflare SSL/TLS encryption mode to “Full” or “Full (strict)”
Broken Assets on Edge CacheCaching HTML immutably prevents browser from fetching new JS/CSS bundlesUse s-maxage for HTML and restrict immutable to hashed static assets
Stale Content After BuildCloudflare edge cache serves old HTML after a new GitHub Pages deploymentPurge Cloudflare Cache via GitHub Actions build workflow API post-deploy step
522 Origin Connection TimeoutGitHub Pages CNAME mismatch or incorrect custom domain setting in repoEnsure repository CNAME file matches the custom domain configured in Cloudflare
CORS Header ErrorsFonts or assets loaded cross-subdomain without explicit CORS permissionInject Access-Control-Allow-Origin: * for static font assets in Worker
Missing Security HeadersWorker modifies headers but forgets to return modified Headers objectReconstruct Response explicitly passing { headers: modifiedHeaders }

Real-World Examples

1. Cloudflare API Cache Purge in GitHub Actions

# Purge Cloudflare edge cache automatically after site deployment
- name: Purge Cloudflare Cache
  run: |
    curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/purge_cache" \
      -H "Authorization: Bearer ${{ secrets.CF_API_TOKEN }}" \
      -H "Content-Type: application.json" \
      --data '{"purge_everything":true}'

2. Standard HSTS Header Injection

// Force HSTS across all subdomains with preload eligibility
headers.set("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload");

3. Edge Redirect for Renamed Paths

// Perform lightweight 301 redirect before origin fetch
if (url.pathname === "/old-docs.html") {
  return Response.redirect("https://example.com/docs/", 301);
}

4. CORS Header for Cross-Origin Web Fonts

// Allow web fonts to be requested cross-origin by external subdomains
if (url.pathname.endsWith(".woff2")) {
  headers.set("Access-Control-Allow-Origin", "*");
}

5. Clickjacking Defense Header

// Deny all framing requests to mitigate clickjacking vulnerability
headers.set("X-Frame-Options", "DENY");

6. Custom 404 Response Page Caching

// Limit edge caching of non-existent resources to 1 minute
if (response.status === 404) {
  headers.set("Cache-Control", "public, max-age=60");
}

7. Removing Sensitive Origin Server Headers

// Strip server fingerprinting metadata from raw origin response
headers.delete("Server");
headers.delete("X-GitHub-Request-Id");

8. Forcing HTTPS Protocol Upgrade

// Redirect incoming insecure HTTP requests to secure HTTPS
if (url.protocol === "http:") {
  url.protocol = "https:";
  return Response.redirect(url.toString(), 301);
}

9. Immutable Cache Policy for Hashed Bundles

// Set immutable caching for static files located inside /static/ hashed directory
if (url.pathname.startsWith("/static/")) {
  headers.set("Cache-Control", "public, max-age=31536000, immutable");
}

10. Simple Cloudflare Worker Response Modification

// Basic pattern for wrapping origin responses with edge modifications
const res = await fetch(request);
const newRes = new Response(res.body, res);
newRes.headers.set("X-Proxy-By", "Cloudflare-Edge");
return newRes;

Visual

Edge Proxy Processing Pipeline

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        EDGE PROXY ARCHITECTURE                         โ”‚
โ”‚                                                                        โ”‚
โ”‚  [Client Browser]                                                      โ”‚
โ”‚        โ”‚                                                               โ”‚
โ”‚        โ”‚ 1. HTTP Request (https://example.com/docs)                    โ”‚
โ”‚        โ–ผ                                                               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ CLOUDFLARE EDGE NETWORK (PoP)                                    โ”‚  โ”‚
โ”‚  โ”‚                                                                  โ”‚  โ”‚
โ”‚  โ”‚   โ”œโ”€โ”€ A. Check Edge Cache โ”€โ”€โ–บ [HIT] โ”€โ”€โ–บ Return Cached Asset      โ”‚  โ”‚
โ”‚  โ”‚   โ”‚                                                              โ”‚  โ”‚
โ”‚  โ”‚   โ”œโ”€โ”€ B. Execute Edge Workers / Rules                            โ”‚  โ”‚
โ”‚  โ”‚   โ”‚      โ”œโ”€โ”€ Check 301 Redirect Rules (Immediate Response)       โ”‚  โ”‚
โ”‚  โ”‚   โ”‚      โ””โ”€โ”€ Evaluate Request Parameters                         โ”‚  โ”‚
โ”‚  โ”‚   โ”‚                                                              โ”‚  โ”‚
โ”‚  โ”‚   โ””โ”€โ”€ C. [MISS] โ”€โ”€โ–บ Fetch from Origin                            โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                    โ”‚                                   โ”‚
โ”‚                                    โ”‚ 2. Fetch Origin Content           โ”‚
โ”‚                                    โ–ผ                                   โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ GITHUB PAGES ORIGIN SERVER                                       โ”‚  โ”‚
โ”‚  โ”‚                                                                  โ”‚  โ”‚
โ”‚  โ”‚   โ””โ”€โ”€ Serves static HTML/JS/CSS (Cache-Control: max-age=600)    โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                    โ”‚                                   โ”‚
โ”‚                                    โ”‚ 3. Raw Response Payload           โ”‚
โ”‚                                    โ–ผ                                   โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ CLOUDFLARE EDGE MODIFICATION                                     โ”‚  โ”‚
โ”‚  โ”‚                                                                  โ”‚  โ”‚
โ”‚  โ”‚   โ”œโ”€โ”€ Inject Security Headers (CSP, HSTS, X-Frame-Options)       โ”‚  โ”‚
โ”‚  โ”‚   โ”œโ”€โ”€ Override Cache-Control (Set s-maxage=86400, immutable)    โ”‚  โ”‚
โ”‚  โ”‚   โ”œโ”€โ”€ Apply Brotli Compression (Compress on-the-fly)           โ”‚  โ”‚
โ”‚  โ”‚   โ””โ”€โ”€ Strip Server Identifiers (Remove Server, X-GitHub-ID)     โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                    โ”‚                                   โ”‚
โ”‚                                    โ”‚ 4. Augmented HTTP Response        โ”‚
โ”‚                                    โ–ผ                                   โ”‚
โ”‚  [Client Browser] (Secured, Compressed & Optimized)                    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Layered Caching Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      MULTI-TIERED CACHE EXPIRATION                     โ”‚
โ”‚                                                                        โ”‚
โ”‚  [Client Request]                                                      โ”‚
โ”‚        โ”‚                                                               โ”‚
โ”‚        โ–ผ                                                               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ TIER 1: BROWSER CACHE                                            โ”‚  โ”‚
โ”‚  โ”‚ Asset: /assets/app-a1b2c3.js                                     โ”‚  โ”‚
โ”‚  โ”‚ Cache-Control: max-age=31536000, immutable                       โ”‚  โ”‚
โ”‚  โ”‚ Result: Immediate local disk load (0ms network cost)             โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                    โ”‚ Cache Miss / HTML Revalidation    โ”‚
โ”‚                                    โ–ผ                                   โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ TIER 2: CLOUDFLARE EDGE POP                                      โ”‚  โ”‚
โ”‚  โ”‚ Document: /index.html                                            โ”‚  โ”‚
โ”‚  โ”‚ Cache-Control: s-maxage=86400 (24-Hour Global Edge Cache)         โ”‚  โ”‚
โ”‚  โ”‚ Result: Edge POP response (<15ms latency)                        โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                    โ”‚ Cache Purge / Edge Miss           โ”‚
โ”‚                                    โ–ผ                                   โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ TIER 3: GITHUB PAGES ORIGIN                                      โ”‚  โ”‚
โ”‚  โ”‚ Origin Default: max-age=600 (10-Minute Origin Fallback)          โ”‚  โ”‚
โ”‚  โ”‚ Result: Shields origin from traffic spikes                       โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Edge 301 Redirect vs Origin Fetch Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   EDGE REDIRECT EXECUTION PATHWAY                      โ”‚
โ”‚                                                                        โ”‚
โ”‚  [Client Browser] โ”€โ”€โ–บ Requests `/old-path`                             โ”‚
โ”‚                             โ”‚                                          โ”‚
โ”‚                             โ–ผ                                          โ”‚
โ”‚              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                          โ”‚
โ”‚              โ”‚ Cloudflare Edge Worker Check โ”‚                          โ”‚
โ”‚              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                          โ”‚
โ”‚                             โ”‚                                          โ”‚
โ”‚           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                        โ”‚
โ”‚           โ”‚ Is Path in Redirect Dictionary?  โ”‚                        โ”‚
โ”‚           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                        โ”‚
โ”‚                    โ”‚                 โ”‚                                 โ”‚
โ”‚              YES   โ”‚                 โ”‚   NO                            โ”‚
โ”‚                    โ–ผ                 โ–ผ                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ Return 301 Immediately    โ”‚  โ”‚ Proxy Request to GitHub Origin    โ”‚  โ”‚
โ”‚  โ”‚ Location: `/new-path`     โ”‚  โ”‚ `username.github.io/path`         โ”‚  โ”‚
โ”‚  โ”‚ (Origin Never Contacted)  โ”‚  โ”‚ (Normal Fetch Pipeline)           โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ItemValue
Edge Proxy ToolingCloudflare Workers / Transform Rules
SSL/TLS ModeFull (strict)
Recommended HSTS TTLmax-age=31536000 (1 Year)
Compression StandardBrotli (15โ€“25% smaller than Gzip)
Edge HTML TTL Strategys-maxage=86400 (24 Hours)
Asset Immutability TTLmax-age=31536000, immutable
Redirect Status Code301 Moved Permanently
Edge Purge AutomationCloudflare Zone API post-deploy step

Key takeaways:

  • GitHub Pages acts as an immutable static origin. Because you cannot modify Nginx configurations on GitHub’s infrastructure, an edge proxy network like Cloudflare is required to intercept and transform HTTP traffic.
  • Custom HTTP security headers protect static sites. Injecting Content-Security-Policy, Strict-Transport-Security, and X-Frame-Options at the edge prevents XSS, clickjacking, and protocol downgrade attacks.
  • Edge 301 redirects preserve SEO value. Moving routes via Cloudflare Workers or Dynamic Redirect Rules returns native HTTP 301 headers instantly without touching the origin or relying on client-side JavaScript refreshes.
  • Brotli compression lowers network payload sizes. Enabling Brotli at the edgeproxy layer compresses static HTML, CSS, and JS assets up to 25% more effectively than native GitHub Pages Gzip.
  • Layered cache policies reduce origin dependencies. Setting high s-maxage edge cache values and immutable browser cache headers offloads over 95% of traffic from GitHub Pages, eliminating origin rate-limiting risks.

Remember: Placing Cloudflare in front of GitHub Pages turns a basic static host into an enterprise-grade web delivery network. By delegating security headers, 301 redirects, Brotli compression, and caching strategies to Cloudflare Workers and Rules, you preserve GitHub Pages’ zero-maintenance deployment workflow while delivering elite speed and compliance.

Was this helpful?


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!