Most engineering portfolios fall into one of two traps. Either they ship a bare-bones HTML page with no visual craft, or they boot a client-side React and Three.js bundle that forces every visitor—and every search crawler—to download hundreds of kilobytes of JavaScript before reading a single paragraph.
When I rebuilt this site, I wanted both: tactile 3D objects and spring-physics motion on capable desktops, alongside a static-first core that keeps standard content pages around 23 KB of HTML, CSS, and JavaScript gzipped, plus 92.09 KB of cached site-wide fonts. You can inspect the full architecture in the engineering case study or see how I apply these same budgets on web and mobile product builds.
Here is how the numbers actually work, what had to be cut to stay under budget, and where the trade-offs sit.
Measuring the real transfer budget
Every npm run build runs scripts/size-budget.mjs, which gzips the built files in dist/ and writes src/data/site-stats.json. That means the numbers reported on this site are measured from the actual production output rather than estimated once during planning.
| Route | Class | HTML (KB) | CSS (KB) | JS (KB) | Fonts (KB) | Total (KB) |
|---|---|---|---|---|---|---|
/ (Home) |
heavy | 15.18 | 16.54 | 8.75 | 92.09 | 132.57 |
/about |
content | 9.45 | 12.75 | 4.83 | 92.09 | 119.12 |
/hire |
content | 11.78 | 12.75 | 5.82 | 92.09 | 122.44 |
/work/this-website |
heavy | 11.65 | 12.75 | 5.10 | 92.09 | 121.58 |
/writing |
content | 5.67 | 12.75 | 5.53 | 92.09 | 116.03 |
The site-wide budgets in site-stats.json cap content routes at 50 KB HTML, 30 KB CSS, and 15 KB JS, and heavy routes at 80 KB HTML, 35 KB CSS, and 70 KB JS, with a 110 KB ceiling for fonts. Once the cached WOFF2 font files are in the browser cache after the first page load, subsequent page navigations transfer roughly 24 to 40 KB gzipped.
Why Astro 7 static output replaced a React SPA
The previous version of this site was a client-rendered React single-page application using React Three Fiber. Even for a static text page, the browser had to parse the React runtime, hydrate the component tree, and wait for external font stylesheets before painting final typography.
Switching to Astro 7 (output: 'static', build.format: 'file', trailingSlash: 'never') flipped the default. Every route compiles to plain semantic HTML at build time. Interactive pieces—the theme toggle, command palette, work filters, and search—run as small vanilla TypeScript custom elements (<x-name>) instead of hydrating a virtual DOM.
The trade-off is that cross-page transitions rely on native browser @view-transition CSS rather than a client-side router. Browsers without cross-document View Transitions fall back to standard multi-page navigation with zero JavaScript overhead.
Pinning variable font axes to stay under 110 KB
Fonts are usually the silent killer of a performance budget. Shipping the full Google Sans Flex variable font pushed the main WOFF2 file to 242 KB—more than double the entire 110 KB font budget before adding a monospace face.
Using fonttools at build time, I subset the Latin character set and pinned the opsz (optical size) and ROND (roundness) axes to their default values while keeping wght (300–800) and wdth (75–100) variable. Paired with a rupee symbol face and JetBrains Mono for technical labels, total site-wide fonts dropped to 92.09 KB gzipped.
The trade-off is that display headings do not use automatic optical-size interpolation. Metric-matched Arial and Consolas fallbacks sit behind font-display: swap to minimize cumulative layout shift while the WOFF2 files download.
Capability detection and lazy-loading Three.js
Shipping 3D on a personal site only makes sense if low-power devices, slow connections, and visitors who prefer reduced motion never pay the cost. Before the main stylesheet loads, a 352-byte inline script in <head> runs detectTier() from src/lib/capability.ts and sets data-motion on <html>:
export type MotionTier = 'static' | 'lite' | 'full';
export function detectTier(env: CapabilityEnv): MotionTier {
if (env.reducedMotion) return 'static';
if (env.saveData) return 'lite';
if (env.cores !== undefined && env.cores < 4) return 'lite';
if (env.memoryGB !== undefined && env.memoryGB < 4) return 'lite';
if (!env.webgl2) return 'lite';
return 'full';
}
In HomeHero.astro, the initial paint renders a static WebP image (/media/hero/workshop.webp) with fetchpriority="high". Only on the full tier—and only after the browser load event and idle callback—does the page import src/lib/workshop-scene.ts, which builds five procedural Three.js objects (a 14-tooth gear, code brackets, AI node, video frame, and cube) with normal and wireframe blueprint materials.
If a visitor is on a low-memory phone, has Data Saver enabled, or sets prefers-reduced-motion: reduce, Three.js is never downloaded or executed.
Solving spring physics at build time instead of runtime
Hand-guessing cubic-bezier() values rarely feels like a physical mechanism, yet importing a runtime spring-physics library on every page adds unnecessary JavaScript. Instead, src/lib/spring-math.ts integrates underdamped, critical, and overdamped spring equations (mass = 1) at build time using a 0.1% settle threshold.
Running npm run springs generates two synchronized outputs from one source:
src/styles/motion.css: CSS custom properties using the nativelinear()timing function so hover states, cards, and modals get authentic spring overshoot directly on the browser compositor.src/lib/springs.ts: Matching TypeScript spring constants for any canvas or GSAP interaction that needs identical timing.
A unit test (src/lib/springs.test.ts) fails if the generated CSS and TypeScript files drift out of sync with the math solver.
Automated post-build gates that prevent regressions
Performance budgets fail silently when they rely on manual discipline. Every npm run build executes four Node verification scripts using parse5 against the generated dist/ directory:
check-content.mjs: Enforces one<h1>per page,<title>length ≤ 60 characters, meta descriptions between 120 and 160 characters, answer summaries between 40 and 70 words, minimum word counts per route type, and zero banned marketing words or placeholder strings.check-links.mjs: Verifies every internal link and anchor across all built HTML pages with zero broken targets or redirect chains.validate-schema.mjs: Parses every JSON-LD<script>block and confirms that every@idreference resolves cleanly to the shared#personand#websitegraph.size-budget.mjs: Measures gzipped HTML, CSS, JS, and font sizes per route and fails the build if any page crosses its class budget.
Checklist for keeping a content-and-3D site fast
If you are planning a portfolio or marketing site with interactive 3D or rich motion, apply these five rules before writing components:
- Render a static fallback first: Never block Largest Contentful Paint on WebGL initialization. Paint a compressed WebP or SVG poster immediately and crossfade the canvas after idle.
- Gate heavy scenes by hardware and preferences: Check
prefers-reduced-motion,saveData,hardwareConcurrency,deviceMemory, and WebGL2 support before fetching 3D chunks. - Subset and pin variable fonts: Strip unused glyphs and pin variable axes you do not animate (
opsz,ROND) so fonts stay under 100–110 KB total. - Bake motion curves at build time: Emit CSS
linear()functions from a spring solver instead of shipping a runtime animation engine for standard UI transitions. - Enforce budgets in CI: Fail the build automatically when a dependency, font, or unoptimized asset pushes a route past its transfer ceiling.






