PERFORMANCE & SEO · PUBLISHED · 2026-12-03
Engineering a Bilingual EN/AR Portfolio on Cloudflare Workers with Zero TBT & Agentic Discovery
Replacing WebGL overhead with idle-deferred 2D canvas, inlining CSS, responsive WebP srcSet, strict CSP, llms.txt, and ARD.
Cloudflare Workers · Vite · Pre-rendered Markdown · llms.txt · ARD · Cloudflare D1
A software engineer's portfolio is itself a production system. Treating sanad.id.ly as an engineering artifact meant holding it to the same architectural standards as client platforms: fast initial paint without main-thread contention, bilingual English/Arabic (LTR/RTL) support, zero-cookie edge APIs, strict security headers, and first-class discoverability for both search crawlers and AI agents.
This post documents the concrete technical decisions implemented in this repository—every one verifiable directly in vite.config.ts, PixiSmoke.tsx, Hero.tsx, worker/index.ts, wrangler.jsonc, and public/_headers.
1. Edge Architecture: Cloudflare Workers + D1 + Selective Asset Bypass
The site runs on Cloudflare Workers (wrangler.jsonc) with a static dist/ asset bundle (binding: "ASSETS", not_found_handling: "single-page-application") paired with a Cloudflare D1 database (portfolio-db) for inquiries and engineering-notes subscribers.
Rather than routing every image and hashed JavaScript chunk through Worker compute, wrangler.jsonc configures run_worker_first selectively:
{
"name": "portfolio",
"main": "worker/index.ts",
"compatibility_date": "2026-12-02",
"assets": {
"directory": "./dist",
"binding": "ASSETS",
"not_found_handling": "single-page-application",
"run_worker_first": [
"/*",
"!/assets/*",
"!/images/*",
"!/favicon.svg",
"!/og.webp"
]
}
}
With negative exclusions (!/assets/*, !/images/*, !/favicon.svg, !/og.webp), static media and immutable bundles serve straight from the edge cache, while HTML routes and /api/* endpoints enter worker/index.ts. Inside the Worker:
- Requests to
www.sanad.id.lyreceive a canonical301redirect tohttps://sanad.id.ly. POST /api/*routes enforce origin validation (isAllowedOrigin), honeypot filtering (body.website), and server-side Cloudflare Turnstile verification (https://challenges.cloudflare.com/turnstile/v0/siteverifyusingCF-Connecting-IP).- Validated submissions persist via parameterized D1 statements (
env.DB.prepare(...).bind(...).run()) while Telegram alerts dispatch non-blockingly withctx.waitUntil(...).
2. Eliminating Main-Thread Blocking: Idle-Deferred 24fps 2D Canvas Smoke
Ambient hero animations often degrade Total Blocking Time (TBT) when a WebGL renderer initializes synchronously on mount and ticks at 60fps. In Hero.tsx, the atmospheric smoke layer (PixiSmoke) is code-split via React.lazy inside <Suspense fallback={null}> so it never blocks first paint.
Inside src/components/portfolio/PixiSmoke.tsx, the implementation avoids heavy WebGL shaders in favor of a lightweight 2D Canvas pipeline:
- Pre-rendered offscreen sprites: At startup,
createSmokePuffgenerates three128x128radial-gradient puff canvases once instead of computing gradients per frame. - Idle-deferred initialization: Startup waits for
window.requestIdleCallback(start, { timeout: 1200 })(with a180mssetTimeoutfallback) so hydration and critical user interactions finish first. - 24fps frame pacing:
FRAME_INTERVAL_MS = 42caps rendering of the18wisps (WISP_COUNT = 18) to roughly 24fps, keeping per-frame main-thread execution sub-millisecond. - Visibility & accessibility awareness: An
IntersectionObserver(threshold: 0.05) anddocument.hiddencheck pause animation whenever the hero leaves the viewport or tab focus. When(prefers-reduced-motion: reduce)matches, it renders a single static frame and exits without schedulingrequestAnimationFrame.
const FRAME_INTERVAL_MS = 42; // ~24 fps keeps main-thread frame time sub-millisecond
const WISP_COUNT = 18;
const loop = (now: number) => {
if (destroyed) return;
rafId = window.requestAnimationFrame(loop);
if (!visible || document.hidden) {
lastTime = now;
return;
}
const deltaMs = now - lastTime;
if (deltaMs < FRAME_INTERVAL_MS) return;
lastTime = now - (deltaMs % FRAME_INTERVAL_MS);
const dtScale = Math.min(deltaMs / 16.67, 4);
elapsed += 0.015 * dtScale;
drawFrame(dtScale, elapsed);
};
3. Zero Render-Blocking CSS via a Post-Build Vite Plugin
Even a small external stylesheet forces an extra network round-trip before First Contentful Paint. In vite.config.ts, a custom post-build plugin (inlineBuiltCssPlugin) intercepts the generated bundle in generateBundle, reads every .css asset, replaces its <link> tag in index.html with an inline <style> block, and removes the standalone .css file from the output:
function inlineBuiltCssPlugin(): Plugin {
return {
name: "inline-built-css",
apply: "build",
enforce: "post",
generateBundle(_options, bundle) {
const htmlAsset = bundle["index.html"];
if (!htmlAsset || htmlAsset.type !== "asset" || typeof htmlAsset.source !== "string") {
return;
}
let html = htmlAsset.source;
for (const [fileName, chunk] of Object.entries(bundle)) {
if (!fileName.endsWith(".css") || chunk.type !== "asset") continue;
const cssText = typeof chunk.source === "string"
? chunk.source
: Buffer.from(chunk.source).toString("utf8");
const linkRegex = new RegExp(
`<link[^>]+href=["']/${fileName.replace(/[.*+?^${}()|[\]\\]/g, "\\
Sanad AlArousi (سند العروسي) | Software Engineer
Engineering systems that endure. Full-stack web, Flutter mobile, backend architecture,
CI/CD pipelines, formal SDLC (PMBOK, SWEBOK, ISO/IEC/IEEE 29148), and open-source developer tools.
سند العروسي — مهندس برمجيات متخصص في الأنظمة المتكاملة وتطبيقات الموبايل والأتمتة وفق المعايير الهندسية.
Portfolio Sections & Documentation
- English Portfolio Home
- النسخة العربية — الصفحة الرئيسية
- Products & Engineering Packages
- Selected Software Projects & Open Source
- Career Experience & Deliverables
- Engineering Blog & Technical Articles
- LLMs & AI Agent Directory (llms.txt)
Core Stack: TypeScript, React, Flutter, Python, Django REST, ERPNext, PostgreSQL, Docker, Cloudflare Workers.
Notable Systems: LibreOffice-MCP, Overcast Cloud Platform, Masayef (Ministry of Youth), Export119.
Contact: me@sanad.id.ly