Sub-400ms LCP Next.js 16 on 1 GB VMs Behind Cloudflare
How this portfolio runs Next.js 16 standalone, multi-cloud 1 GB Linux VMs, Nginx RSC-safe caching, and Docker deploys for zero hosting cost.
The Constraint: Free-Tier 1 GB RAM VMs
Everything powering whoisdhruv.com is free except the domain name. The app runs as Docker images built by GitHub Actions and deployed to small 1 GB Linux VMs across Oracle Cloud, GCP, and Azure, sitting behind Nginx and Cloudflare.
On a 1 GB VM, you cannot brute-force latency with oversized Node heaps or uncached SSR renders. Sub-400ms LCP comes from doing less work per request and making sure the right layers cache the right bytes.
Browser -> Cloudflare Edge -> Nginx (RSC-safe cache) -> Next.js 16 StandaloneNext.js 16 Standalone + Static-First Routes
Packaging Next.js with output: 'standalone' strips node_modules down to the exact runtime dependency graph, which keeps Docker images lean and cold container restarts fast.
- Static by default: Pages like
/,/about,/projects,/notes, and the markdown mirrors (/llms.txt,/projects.md,/notes.md) compile asforce-staticroutes. Node serves pre-rendered responses directly from memory/disk instead of running React renders on every hit. - Dynamic only where state demands it: Routes that actually mutate or read live data—like
/guestbook(revalidate = 60),/api/chat, and/api/voice/*—bypass static caching cleanly. - Precomputed RAG embeddings: Rather than querying an embedding API on startup or per request,
content/facts/**andcontent/notes/**are embedded at build time into a compact JSON bundle shipped inside the image.
Nginx Caching Without Breaking React Server Components
App Router introduces a subtle caching trap: the same URL path (/about) can be requested either as full HTML (initial document navigation) or as an RSC flight payload (client-side next/link transition carrying the RSC: 1 header).
If a reverse proxy keys its cache only on $scheme$request_method$host$request_uri, a client-side RSC fetch can poison the cache and serve raw flight text to the next full-page reload—or vice versa.
# Include RSC/router headers in the cache key so HTML and flight payloads never collide
proxy_cache_key "$scheme$request_method$host$request_uri|$http_rsc|$http_next_router_state_tree|$http_next_router_prefetch";Separating the cache key by $http_rsc and Next router headers eliminates HTML/RSC collisions completely while still giving repeat visitors single-digit millisecond origin responses.
Never cache an App Router URL by URI alone. Always partition proxy cache keys byRSCand Next router headers—or serve dedicated static routes (like/notes.md) with cleantext/markdowncontent types instead ofAccept-header content negotiation.
Shipping Safely on Small Boxes
A single OOM kill during a deploy can take down a 1 GB VM if you build on the host. Instead:
- Build in CI, not on the VM: GitHub Actions compiles the Next.js standalone app and builds multi-architecture Docker images (including the local TTS runtime). The VM only pulls a finished image and swaps the container.
- Verify locally before trusting the edge: Deploy workflows validate each VM's container health, deployed release SHA, and TTS synthesis locally on the host before marking a release live and retaining the previous image for rollback.
- Keep client JS disciplined: Heavy interactive pieces (terminal, voice session, modals) lazy-load on demand so the initial paint stays light on mobile CPUs as well as desktop.