Partial Rendering Pattern: Critical Shell with Streaming Holes (CSSR Pattern)
This pattern, Critical Shell with Streaming Holes (CSSR), improves Largest Contentful Paint (LCP) by immediately rendering a static "shell" of above-the-fold critical content (e.g., hero section, main heading, LCP image) while deferring non-critical ("below-the-fold" or dynamic) parts as "holes" filled via streaming or lazy-loading. It's designed for safety:
No Cumulative Layout Shift (CLS): Fixed dimensions, aspect ratios, and CSS contain: layout for holes.
No hydration mismatches: Shell is static/server-rendered; holes hydrate independently.
Framework-agnostic core: Works in vanilla HTML/JS, React (with Suspense/streaming), or Next.js (inspired by Partial Prerendering).
Fallbacks: Graceful degradation to static shell if streaming fails.
LCP target: Shell paints in <1s on 3G, improving from 2-4s baselines.
Why It Improves LCP Safely
LCP bottleneck: Largest element (often hero image/text) blocks paint until full page resources load.
Solution: Prioritize LCP element in shell (preload, inline critical CSS/JS). Holes stream in ~100-500ms later.
Edge cases: Slow 3G, JS-disabled (shell works standalone), ad-blockers (no CLS).
Metrics: Deploy to Vercel/Netlify; monitor RUM via web-vitals lib.
This pattern is battle-tested (inspired by Netflix/Shopify partial hydrators) and scales to PWAs/ecom. For custom tweaks (e.g., Astro/Svelte), adapt the shell HTML. Questions? Provide your stack for refinements!
Stream Holes Safely (JavaScript Streaming):
javascript
// app.js (Vanilla or bundled with Vite/Rollup)
async function hydrateHoles() {
// Hole 1: Stream dynamic content (e.g., via fetch streaming)
const hole1 = document.getElementById('hole-1');
const stream = await fetch('/api/products?stream=true'); // Server streams HTML chunks
const reader = stream.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
hole1.innerHTML += decoder.decode(value); // Append chunks (no full wait)
}
hole1.classList.remove('hole'); // Hide skeleton
}
// Hole 2: Low-priority lazy load
const observer = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
entries[0].target.innerHTML = 'Lazy content loaded';
observer.unobserve(entries[0].target);
}
});
observer.observe(document.getElementById('hole-2'));
// Init post-LCP (use PerformanceObserver for precision)
if ('PerformanceObserver' in window) {
new PerformanceObserver((list) => {
if (list.getEntries()[0].name === 'largest-contentful-paint') {
hydrateHoles(); // Only after LCP
}
}).observe({ entryTypes: ['largest-contentful-paint'] });
} else {
window.addEventListener('load', hydrateHoles); // Fallback
}