Architecture Showcase · v2.5.0
AstroPress
Decoupled publishing bridge connecting WordPress editorial authoring with Astro SSR on Cloudflare Pages and Workers. Features 4-tier edge caching, pure PHP SigV4 media offload to Cloudflare R2, and sub-150ms cache revalidation.
Edge Latency
Direct POP HIT from 330+ Cloudflare edge nodes
Core Web Vitals
0.38s LCP, 0.00 CLS, zero hydration penalty
SigV4 PHP Core
Zero external AWS SDK dependencies
Egress Bandwidth
Cloudflare R2 media hosting without egress fees
Architecture Dataflow
End-to-end execution from WordPress editor to visitor delivery
Dual-Engine Invalidation
Cloudflare Zone & Worker Cache Purge
The Astro /api/revalidate endpoint verifies HMAC secret authenticity, calls Cloudflare API v4 to instantly purge affected URLs from the global Zone Cache (<150ms), and invokes caches.default.delete() inside Worker memory.
4-Tier Caching Architecture
Layered retention delivering sub-millisecond responses while guaranteeing immediate editorial cache invalidation
Redis Object Cache & LiteSpeed REST
Serializes WP REST API responses in Redis RAM memory and intercepts cache purges, shielding origin MySQL queries when Astro edge servers request raw content.
1-Year Cloudflare Edge Retention
Serves pre-rendered HTML shells as cf-cache-status: HIT across 330+ Cloudflare edge POP nodes using s-maxage=31536000.
Worker caches.default Deduplication
Intercepts inbound requests in Cloudflare Worker middleware prior to SSR route execution, matching against Edge Cache API to prevent duplicate compute overhead.
Conditional Revalidation (max-age=0)
Visitors receive max-age=0, must-revalidate, triggering lightweight 304 conditional checks against the nearest POP for instant editorial sync.
Companion Plugin Features
Unified WordPress companion plugin replacing multiple third-party extensions
Pure PHP SigV4 Media Engine
Lightweight (<35 KB) AWS Signature v4 client for Cloudflare R2 offloading without the 50MB AWS SDK. Supports dual storage and custom CDN domains.
Non-Blocking Webhook Purge
Dispatches non-blocking async HTTP POST sockets on PHP shutdown with micro-queue debouncing, triggering Cloudflare edge purges in under 150ms.
Dual-Engine Edge Warmer
Pre-warms purged URLs across Cloudflare POP nodes immediately after cache eviction to eliminate first-visitor cold boots.
Rank Math & Yoast Bridge
Exposes fully rendered HTML head metadata via REST endpoints, syncing schema JSON-LD, OpenGraph, and 301/302 redirects to edge middleware.
Dual-Stage Image Optimizer
Automated WebP and AVIF generation on upload, stripping heavy metadata while maintaining full fallback compatibility.
Native Update Pipeline
Direct GitHub release updates using WordPress Core's Plugin_Upgrader sandbox, including one-click rollback to historical releases.
Production Deployments
High-traffic platforms running the AstroPress architecture in production
TopNepali.com
National election and digital publishing platform serving millions of monthly pageviews across 753 palikas and 165 parliamentary constituencies with zero downtime during peak surges.
Grisma Portfolio & Tools
Astro SSR architecture on Cloudflare Pages Advanced Mode. Features instantaneous technical search, interactive civic calculators, and sub-150ms cache invalidations.
Implementation Blueprints
Production-ready edge handlers for Astro and Cloudflare Workers
// src/pages/api/revalidate.ts
import type { APIRoute } from 'astro';
export const POST: APIRoute = async ({ request, locals }) => {
const payload = await request.clone().json().catch(() => ({}));
const { slug, type, action, urls, secret } = payload;
// 1. Verify shared secret token
const expectedSecret = (locals as any)?.runtime?.env?.REVALIDATE_SECRET || process.env.REVALIDATE_SECRET;
if (expectedSecret && secret !== expectedSecret) {
return new Response(JSON.stringify({ error: 'Unauthorized handshake' }), { status: 401 });
}
// 2. Instant handshake probe for AstroPress admin dashboard
if (type === 'test' || action === 'ping' || slug === 'test-connection') {
return new Response(JSON.stringify({
success: true,
status: 'connected',
framework: 'Astro SSR on Cloudflare Edge',
timestamp: Date.now()
}), { status: 200 });
}
// 3. Resolve affected route paths
const affected: string[] = Array.isArray(urls) && urls.length > 0
? urls
: (slug ? ['/' + slug.replace(/^\//, '')] : ['/']);
if (!affected.includes('/')) affected.push('/');
// 4. Invalidate Cloudflare Worker caches.default in-memory store
try {
const cache = (globalThis as any).caches?.default;
if (cache) {
for (const u of affected) {
const targetUrl = new URL(u, request.url).href;
await cache.delete(new Request(targetUrl));
}
}
} catch (err) {
console.error('Worker cache delete error:', err);
}
// 5. Trigger Cloudflare Zone Cache API purge (<150ms)
const cfZoneId = (locals as any)?.runtime?.env?.CF_ZONE_ID || process.env.CF_ZONE_ID;
const cfApiToken = (locals as any)?.runtime?.env?.CF_API_TOKEN || process.env.CF_API_TOKEN;
const frontendUrl = (locals as any)?.runtime?.env?.FRONTEND_URL || process.env.FRONTEND_URL;
let cfPurged = false;
if (cfZoneId && cfApiToken && frontendUrl) {
try {
const purgeUrls = affected.map(u => new URL(u, frontendUrl).href);
const cfRes = await fetch(`https://api.cloudflare.com/client/v4/zones/${cfZoneId}/purge_cache`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${cfApiToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ files: purgeUrls })
});
cfPurged = cfRes.ok;
} catch (e) {
console.error('CF Zone Purge error:', e);
}
}
// 6. Pre-warm canonical routes to eliminate visitor cold boots
if (frontendUrl) {
for (const u of affected) {
fetch(new URL(u, frontendUrl).href, {
headers: { 'User-Agent': 'AstroPress-EdgeWarmer/2.5' }
}).catch(() => {});
}
}
return new Response(JSON.stringify({
success: true,
revalidated: true,
purged: affected,
cfPurged
}), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
}; Quickstart Guide
Four steps to deploy AstroPress on your WordPress and Astro installations
Install Companion Plugin
Download astropress.zip from GitHub Releases and install via WordPress Plugins > Add New > Upload.
Connect R2 Storage
Navigate to AstroPress > Cloudflare R2 and enter a scoped Cloudflare API token. Buckets and Account ID are auto-discovered.
Configure Edge Bridge
Set your Astro frontend URL and shared REVALIDATE_SECRET in AstroPress > Headless Bridge to verify webhook connectivity.
Deploy Astro Edge Handlers
Add src/pages/api/revalidate.ts to your Astro project and deploy to Cloudflare Pages or Workers.