Serverless Architecture

StackPages is built entirely on Cloudflare Workers, providing a global, high-performance, and secure foundation for your content.

Edge Rendering

Unlike traditional servers, our Worker runs on Cloudflare's global network. Every request is handled by the data center closest to the user, ensuring near-zero latency. HTML is generated dynamically at the edge, combining static templates with dynamic content.

Universal Feed Parser

The Worker acts as a universal adapter. It fetches RSS feeds from Substack, YouTube, and Podcast hosts, parses the XML, and transforms it into a unified JSON structure. This allows you to use any content source without changing your frontend code.

HTMX Native

The backend is aware of HTMX. When it detects an `HX-Request` header, it returns only the necessary HTML fragment (like a card or a list) instead of the full page. This creates a Single Page Application (SPA) feel without the complexity of client-side frameworks.

Smart Caching

To minimize latency and avoid hitting rate limits on external APIs, the Worker implements a smart caching strategy. Parsed feed data is cached using the Cache API and KV storage, ensuring that your site remains fast and available even if the source feeds are slow or down.

Worker Logic Snippet

// Example of Edge Routing Logic
export default {
  async fetch(req, env) {
    const url = new URL(req.url);
    
    // 1. HTMX Detection
    const isHtmx = req.headers.get("HX-Request") === "true";
    
    // 2. Route Handling
    if (url.pathname === "/api/posts") {
      const posts = await getCachedRSS(env.SUBSTACK_URL);
      
      if (isHtmx) {
        // Return HTML fragment for HTMX
        return generatePostCards(posts);
      }
      
      // Return JSON for API
      return Response.json(posts);
    }
    
    // 3. Static Asset Fallback
    return env.ASSETS.fetch(req);
  }
}