Choosing between Server-Side Rendering (SSR) and Static Site Generation (SSG) significantly impacts both web performance and SEO. This guide compares approaches and provides optimization strategies for each.
The Rendering Spectrum
Modern web frameworks offer multiple rendering strategies:
- Static Site Generation (SSG): Pre-built at build time
- Incremental Static Regeneration (ISR): Static with periodic updates
- Server-Side Rendering (SSR): Generated on each request
- Client-Side Rendering (CSR): Rendered in the browser
- On-Demand Revalidation: Hybrid approach
SSG: Best for Performance and SEO
Advantages
- Fastest TTFB (served from CDN)
- Best Core Web Vitals scores
- Perfect crawlability for search engines
- Reduced server costs
- Edge cacheable
Ideal Use Cases
- Blog posts and articles
- Product pages with infrequent changes
- Documentation sites
- Landing pages
- Marketing websites
SSG Implementation (Next.js)
export async function getStaticProps() {
const posts = await fetchPosts();
return {
props: { posts },
revalidate: 3600, // ISR: regenerate every hour
};
}
SSR: When Dynamic Content is Essential
Advantages
- Always fresh content
- Personalized responses
- Good for frequently updated data
- Better for user-specific pages
SEO Challenges
- Higher TTFB
- Server capacity affects crawl budget
- Harder to cache at edge
- Crawler timeout risk on slow servers
SSR Optimization
// Cache SSR responses at edge
export async function getServerSideProps({ res }) {
const data = await fetchData();
res.setHeader('Cache-Control', 'public, s-maxage=60, stale-while-revalidate=300');
return { props: { data } };
}
Hybrid Rendering Strategy
The best approach combines rendering methods:
| Page Type | Rendering | Cache |
|---|---|---|
| Homepage | ISR | 5 min |
| Blog posts | SSG | 1 hour revalidation |
| Product pages | ISR | 15 min revalidation |
| User dashboard | SSR | No cache |
| Search results | SSR | 1 min cache |
| API routes | SSR | Dynamic |
Performance Optimization for Each Strategy
SSG Optimizations
- Preload critical resources in HTML
- Implement service worker for offline support
- Use CDN with geo-distribution
- Optimize build output size
SSR Optimizations
- Implement edge caching
- Use streaming SSR for progressive rendering
- Cache database queries
- Use connection pooling
- Implement server-side compression
Streaming SSR
// React 18 streaming SSR
import { renderToPipeableStream } from 'react-dom/server';
app.get('/', (req, res) => {
const stream = renderToPipeableStream(
<App />,
{
bootstrapScripts: ['/client.js'],
onShellReady() {
res.setHeader('content-type', 'text/html');
stream.pipe(res);
}
}
);
});
Impact on Core Web Vitals
| Metric | SSG | SSR | CSR |
|---|---|---|---|
| LCP | Best | Good | Poor |
| FCP | Best | Good | Poor |
| INP | Same | Same | Poor |
| CLS | Good | Good | Variable |
| TTFB | Best | Variable | N/A |
Crawl Budget Considerations
SSR sites consume more crawl budget:
- Server must render each page on crawl
- Slow responses reduce crawl rate
- Use
Crawl-Delayin robots.txt if needed - Implement XML sitemap for efficient discovery
SSG sites are crawler-friendly:
- Static HTML served instantly
- Crawler can request pages rapidly
- No server load from crawling
- Better crawl efficiency