The Interactive Islands pattern hydrates only components that need JavaScript, keeping static content as plain HTML for better performance.
Key Benefit: Reduced JavaScript execution, faster Time to Interactive (TTI)
✓ No re-renders
✓ Lower memory usage
✓ Faster initial render
✓ Pure HTML rendering
✓ No reactivity overhead
✓ Click events via HTML
✓ Lightweight
✓ One-time render
✓ Perfect for static badges
This accordion requires full JavaScript hydration for interactions.
✓ Full reactivity
✓ Event handling
✓ State management
✓ Two-way binding
✓ Validation
✓ Real-time updates
✓ Live counting
✓ Dynamic feedback
✓ Requires JS
import { scanAndHydrate } from './utils/partial-hydration.js';
// Automatically optimize all components
window.addEventListener('DOMContentLoaded', () => {
const stats = scanAndHydrate(document.body, { debug: true });
console.log('Static:', stats.static);
console.log('Interactive:', stats.interactive);
console.log('Savings:', stats.savings);
});
import { markAsStatic, markAsInteractive } from './utils/partial-hydration.js';
// Static component (no updates needed)
class USAButton extends LitElement {
constructor() {
super();
markAsStatic(this); // Optimized rendering
}
}
// Interactive component (full reactivity)
class USAModal extends LitElement {
constructor() {
super();
markAsInteractive(this); // Full features
}
}
import { markAsStatic, hydrateComponent } from './utils/partial-hydration.js';
// Start static
markAsStatic(button);
// Later, make interactive based on user action
document.getElementById('enable-features').addEventListener('click', () => {
hydrateComponent(button); // Now fully interactive
});