Server-Side Rendering (SSR)
The server generates HTML for each request.How It Works
- User requests
/users - Server fetches data from database
- Server renders HTML template
- Server sends complete HTML
- Browser displays page immediately
Example with HTMX
Pros
- SEO-friendly: Search engines see full HTML
- Fast initial load: No JavaScript needed
- Works without JS: Functional even if JS disabled
- Simpler: No client-side routing or state management
Cons
- Server load: Server renders every page
- Full page reloads: Less smooth than SPA
- Network dependency: Requires server for every action
- Less interactive: Limited client-side interactivity
Single-Page Application (SPA)
The browser loads once, then JavaScript handles all interactions.How It Works
- User visits site
- Server sends minimal HTML + JavaScript bundle
- JavaScript loads and runs
- JavaScript fetches data via API
- JavaScript updates DOM
Example with React
Pros
- Smooth UX: No page reloads
- Rich interactions: Complex UI possible
- Offline capable: Can work offline with service workers
- Reduced server load: Server only handles API requests
Cons
- SEO challenges: Requires extra work for search engines
- Slower initial load: Must download JavaScript first
- Complexity: Client-side routing, state management
- JavaScript required: Doesn’t work without JS
Hybrid Approaches
HTMX with Alpine.js
Server renders HTML, Alpine adds interactivity:- SEO-friendly
- Progressive enhancement
- Minimal JavaScript
SPA with SSR (Next.js, Nuxt)
Generate static HTML at build time:- SEO-friendly
- SPA-like interactions
- Fast initial load
Decision Matrix
| Factor | SSR (HTMX) | SPA (React) | Hybrid |
|---|---|---|---|
| SEO | ✅ Excellent | ⚠️ Requires work | ✅ Excellent |
| Initial load | ✅ Fast | ❌ Slower | ✅ Fast |
| Interactivity | ⚠️ Limited | ✅ Rich | ✅ Good |
| Complexity | ✅ Simple | ❌ Complex | ⚠️ Moderate |
| Offline | ❌ No | ✅ Yes | ⚠️ Partial |
| Server load | ❌ Higher | ✅ Lower | ⚠️ Moderate |
| JS required | ❌ No | ✅ Yes | ⚠️ Partial |
When to Use SSR
Choose SSR (HTMX) when:- SEO is critical
- Simple CRUD operations
- Content-heavy sites
- Team prefers server-side
- Progressive enhancement needed
- Blogs
- Marketing sites
- Admin dashboards
- Documentation sites
When to Use SPA
Choose SPA (React/Vue/Svelte) when:- Rich interactivity needed
- Desktop-like experience
- Complex client-side state
- Offline support needed
- Email clients
- Project management tools
- Design tools
- Real-time dashboards
When to Use Hybrid
Choose Hybrid when:- Need both SEO and interactivity
- Want best of both worlds
- Content + interactive features
- E-commerce (product pages + cart)
- Social media (feeds + messaging)
- SaaS apps (marketing site + app)