01. The JavaScript Tax
Amateur developers treat modern frontend frameworks like default skin presets — they spin up a heavy Single Page Application (SPA) with full client-side hydration for a simple static landing page or portfolio.
When you do this, you pass a massive JavaScript Tax down to the user. The browser has to download megabytes of JS, parse it, compile it, and execute it before the user can even read a sentence. This destroys your Core Web Vitals and plummets your SEO ranking.
The Structural Rule: Do not ship JavaScript to the browser unless it is absolutely required for dynamic user interactivity. Treat JS as a premium enhancement, not your baseline infrastructure.
The Real Cost of JavaScript
Every kilobyte of JavaScript has a compounding cost:
| Bundle Size | Parse + Compile Time | Impact |
|---|---|---|
| 50 KB | ~100ms | Negligible — good budget for interactive components |
| 100 KB | ~200ms | Acceptable — typical for a well-optimized SPA |
| 250 KB | ~500ms | Noticeable — mobile users feel the delay |
| 500 KB | ~1s+ | Critical — Lighthouse score drops, bounce rate spikes |
| 1 MB+ | ~2s+ | Unusable — most mobile users leave before content appears |
The hidden multiplier: JavaScript isn’t just downloaded — it’s parsed, compiled, AND executed. A 200KB JS bundle can take 400ms+ to become interactive on a mid-range Android phone. Meanwhile, a pure HTML page renders in under 50ms.
The JS Budget Framework
Before choosing any framework, set a JavaScript budget:
| Metric | Target | What It Means |
|---|---|---|
| Total JS | < 200 KB (gzipped) | Total JavaScript sent to browser |
| First Contentful | < 1.0s | When first text/image appears |
| Largest Paint | < 2.5s | When main content is visible |
| Time to Interactive | < 3.0s | When user can click buttons |
| Cumulative Layout Shift | < 0.1 | Elements don’t jump around |
If your framework choice can’t meet this budget for your use case, you’ve chosen the wrong framework — not the wrong optimization.
02. The Modern Rendering Spectrum
Before choosing a tool, you must explicitly select your rendering pattern based on two questions:
- How fresh does the content need to be? (Never changes → Changes hourly → Real-time)
- How fast must it load? (Instant → Fast → Acceptable)
FRESHNESS →
<div class="flow">
<div class="flow-step">
<div class="flow-box">
<span class="flow-num">SSG</span>
<span class="flow-label">Static Site Generation</span>
<span class="flow-sub">Build once, serve forever</span>
</div>
</div>
<div class="flow-step">
<div class="flow-arrow"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg></div>
</div>
<div class="flow-step">
<div class="flow-box">
<span class="flow-num">ISR / PPR</span>
<span class="flow-label">Incremental / Partial</span>
<span class="flow-sub">Static shell + fresh data</span>
</div>
</div>
<div class="flow-step">
<div class="flow-arrow"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg></div>
</div>
<div class="flow-step">
<div class="flow-box">
<span class="flow-num">SSR</span>
<span class="flow-label">Server-Side Rendering</span>
<span class="flow-sub">Fresh render per request</span>
</div>
</div>
</div>
| Pattern | Freshness | JS Runtime | Best For |
|---------|-----------|------------|----------|
| **SSG** | Never changes | Zero | Docs, portfolios, blogs |
| **ISR / PPR** | Changes hourly | Minimal | E-commerce, product pages |
| **SSR** | Real-time | Full | Dashboards, user-specific |
~50ms TTFB ~100ms TTFB ~300ms+ TTFB
SSG (Static Site Generation)
The Mechanics: The server compiles the entire website into raw HTML, CSS, and asset files once at build time. When a user requests a page, the CDN serves the pre-baked file instantly.
Best For: Documentation sites, portfolios, corporate landing pages, blogs, marketing pages.
Tell your AI tool: “Create a static landing page with a hero section and layout. The page should be pure HTML with zero JavaScript shipped. Use Astro’s static output mode.”
The limitation: Content is frozen at build time. If your data changes (new blog post, updated price), you must rebuild and redeploy the entire site.
ISR (Incremental Static Regeneration)
The Mechanics: Like SSG, but with a TTL (time-to-live). The page is served from cache, and when the TTL expires, the next request triggers a background revalidation. The user gets the cached version instantly; the fresh version is built and cached for the next user.
Tell your AI tool: “Create a pricing page with ISR. Set revalidation to 3600 seconds (1 hour). The page should fetch fresh prices on each revalidation but serve cached content between refreshes.”
Best For: E-commerce product pages, news articles, any content that changes periodically but doesn’t need real-time freshness.
SSR (Server-Side Rendering)
The Mechanics: The server waits for a user request, queries the database live, renders the HTML on the fly, and sends the completed page. Every request gets fresh content.
Best For: User-specific dashboards, banking portals, real-time feeds, authenticated areas.
// Next.js — SSR (no caching, fresh on every request)
export const dynamic = 'force-dynamic';
export default async function DashboardPage() {
const user = await getUser(); // Fresh auth check
const stats = await getLiveStats(); // Real-time data
return <Dashboard user={user} stats={stats} />;
}
The cost: Higher server load, slower TTFB (Time to First Byte). Every request hits your server and database.
PPR (Partial Prerendering)
The Modern Apex: PPR breaks the binary trade-off between SSG and SSR. At build time, it generates a static HTML shell for parts of the page that never change (navbar, layout, footer) but leaves dynamic holes wrapped in React Suspense boundaries.
PPR Page Structure:
- STATIC (instant): Nav, Hero, Footer — served from CDN in ~20ms
- DYNAMIC (streams): User data, Dashboard metrics — loaded as data arrives
- SKELETON (placeholder): Shown while dynamic content loads
The Execution: The instant a user clicks your link, the edge server ships the static shell immediately (~20ms TTFB). While the user reads the hero, the server streams the dynamic components down the same HTTP request. No extra round trips.
CSR (Client-Side Rendering) — The Legacy Pattern
The Mechanics: The server sends an empty HTML shell with a <div id="root"></div> and a script tag. The browser downloads the JavaScript, which then fetches data and renders everything client-side.
Why it still exists: SPAs built with Create React App, Vue CLI, or Angular CLI use this pattern by default. It was the standard from 2015-2020.
Why you should avoid it for new projects: The user sees a blank screen until the JS loads and executes. No SEO (crawlers see empty HTML). Worst Core Web Vitals of any pattern.
CSR Loading Timeline:
- 0ms: Browser receives empty HTML shell
- 200ms: JS bundle starts downloading
- 500ms: JS bundle finishes downloading
- 700ms: JS starts executing
- 1000ms: API call fires to fetch data
- 1500ms: Data returns, React renders DOM
- 1600ms: User finally sees content
- Total: ~1.6 seconds of blank screen
03. The Decision Framework
Stop asking “React or Next.js?” — that’s the wrong question. The right question is: “What rendering pattern does my content require?”
The Decision Table
| What You’re Building | Rendering Pattern | Framework | Why |
|---|---|---|---|
| Marketing / Landing / Portfolio | SSG | Astro | Zero JS, instant load, perfect SEO |
| Blog / Documentation / Content | SSG + Islands | Astro | Static content, minimal interactive widgets |
| E-commerce product pages | ISR | Next.js | Static shell, prices refresh hourly |
| SaaS dashboard with user data | PPR or SSR | Next.js App Router | Static layout, dynamic user content |
| Real-time collaborative app | CSR + WebSocket | React/Vue | Heavy JS is unavoidable here |
| Hybrid (marketing + app) | Astro + Next.js | Both | Astro for public, Next.js for app behind auth |
The Framework Comparison
| Dimension | Astro | Next.js (App Router) | Remix | SvelteKit |
|---|---|---|---|---|
| Default JS | 0 KB | ~100 KB | ~80 KB | ~30 KB |
| Rendering | SSG default, SSR optional | SSR/SSG/ISR/PPR | SSR default | SSR default |
| Interactivity | Islands (opt-in hydration) | Server/Client Components | Client components | Svelte reactivity |
| Data Loading | getStaticProps equivalent | Server Components + fetch | loader functions | load functions |
| Best For | Content-heavy sites | Full-stack SaaS apps | Form-heavy apps | Performance-critical apps |
| Learning Curve | Low | Medium-High | Medium | Low |
| Ecosystem | Growing | Massive | Moderate | Growing |
| Deployment | Any static host | Vercel (optimal), any Node host | Any Node host | Any Node host |
04. Deep Dive: Astro’s Islands Architecture
Astro treats your page like an ocean of static, high-performance HTML. If an element requires interactivity, you drop that component into the page as an isolated Island.
The master advantage: You choose exactly how and when that component hydrates on the user’s device via client directives.
The Client Directives
Tell your AI tool: “Use Astro’s client directives to control when components hydrate:
- client:load — hydrate immediately (for critical above-fold elements)
- client:idle — hydrate when browser is idle (for below-fold widgets)
- client:visible — hydrate when scrolled into view (for charts, maps)
- client:hydrate — hydrate on user interaction (hover, click, focus)“
Client Directive Cheat Sheet
| Directive | When It Hydrates | Use Case |
|---|---|---|
client:load | Immediately on page load | Critical interactive elements above the fold |
client:idle | When browser is idle | Below-the-fold widgets, search bars |
client:visible | When element enters viewport | Charts, maps, heavy components below fold |
client:media | When a CSS media query matches | Mobile-only navigation, responsive widgets |
client:hydrate | Manual trigger via script | Complex state-driven components |
Real-World Island Example
Tell your AI tool: “Create a dashboard page where:
- Sidebar is static HTML (zero JS)
- StatsCard hydrates when scrolled into view
- LiveActivityFeed hydrates immediately (real-time data)
- PricingToggle hydrates on user interaction”
The result: The page loads as pure HTML (~20KB). The interactive components download their JS individually and hydrate only when needed.
05. Deep Dive: Next.js App Router
Next.js App Router (introduced in v13, stable in v14+) fundamentally changed how React applications are structured. The core shift: Server Components by default.
Server Components vs. Client Components
Server Components run on the server and ship zero JavaScript to the browser. Use them for data fetching, database queries, and static layout.
Client Components run in the browser and ship JavaScript. Use them for user interactions (clicks, inputs), state management, and browser APIs.
Tell your AI tool: “By default, all components are server components in Next.js App Router. Only add ‘use client’ directive when the component needs useState, useEffect, onClick handlers, or browser APIs. Keep everything else as server components to minimize JavaScript bundle.”
The Rule: Server First, Client Only When Necessary
| Use Server Component When… | Use Client Component When… |
|---|---|
| Fetching data from database | Handling user interactions (clicks, inputs) |
| Accessing backend resources directly | Using useState, useEffect, or other hooks |
| Keeping sensitive logic server-side | Using browser APIs (localStorage, window) |
| Reducing client-side JS bundle | Using third-party libraries that require browser runtime |
| Rendering static layout and structure | Animations, transitions, real-time updates |
Streaming and Suspense
PPR in Next.js uses React Suspense to stream dynamic content:
Tell your AI tool: “Use React Suspense to stream dynamic content. Wrap async server components in Suspense with skeleton fallbacks. The static header renders instantly while dynamic content streams in as database queries complete.”
What this does: The user sees the header immediately. Stats stream in when ready. Activity feed streams in when ready. No waterfall. No layout shift (skeletons hold space).
06. Core Web Vitals: The Performance Gate
Google uses three metrics to rank your site. If you fail these, your SEO suffers regardless of how good your content is.
| Metric | What It Measures | Target | How Rendering Pattern Affects It |
|---|---|---|---|
| LCP (Largest Contentful Paint) | When the main content becomes visible | < 2.5s | SSG: ~0.5s. SSR: ~1.5s. CSR: ~3s+ |
| INP (Interaction to Next Paint) | Responsiveness to user input | < 200ms | More JS = worse INP. Islands help. |
| CLS (Cumulative Layout Shift) | Visual stability (things jumping around) | < 0.1 | Skeletons prevent CLS. Dynamic inserts cause it. |
The Performance Budget
{
"budgets": [
{
"resourceType": "script",
"budget": 200000,
"budgetWarning": 150000
},
{
"resourceType": "stylesheet",
"budget": 50000,
"budgetWarning": 30000
},
{
"metric": "largest-contentful-paint",
"budget": 2500,
"budgetWarning": 1800
},
{
"metric": "cumulative-layout-shift",
"budget": 0.1,
"budgetWarning": 0.05
}
]
}
Senior Moves for Performance
- Measure first, optimize second. Run Lighthouse on your actual site before changing anything. You can’t improve what you can’t measure.
- SSG for anything that doesn’t change per-request. If the content is the same for every user, there’s no reason to render it server-side on every request.
- Lazy load everything below the fold. Use
client:visible(Astro) ordynamic()(Next.js) for components that aren’t immediately visible. - Monitor real user data (RUM). Lighthouse is lab data. Use Vercel Analytics, SpeedCurve, or Web Vitals library to see what real users experience.
- Font loading matters. Use
font-display: swapand self-host fonts. Third-party font requests add 200-500ms to LCP.
Key Takeaways
| Concept | Mental Model | Senior Insight |
|---|---|---|
| JavaScript Tax | Every KB costs parse + compile + execute time | Set a budget: < 200KB gzipped for most sites |
| SSG | Build once, serve forever | Best performance, worst freshness — use for content that doesn’t change |
| ISR | Static shell + time-based revalidation | Good for product pages, prices, anything that updates hourly |
| SSR | Fresh render on every request | Use only when content is user-specific or real-time |
| PPR | Static shell + dynamic holes | The modern default — instant TTFB + streaming dynamic content |
| CSR | Empty shell + client-side render | Legacy pattern — avoid for new projects unless building real-time apps |
| Astro Islands | Opt-in hydration per component | Best for content-heavy sites — zero JS unless you explicitly add it |
| Next.js Server Components | Server-first, client only when needed | Dramatically reduces client bundle — most components never ship JS |
| Core Web Vitals | LCP + INP + CLS | Performance is SEO — failing these metrics means less traffic |