Performance: Islands architecture in Fresh
This affects page load speed by reducing JavaScript bundle size and improves interaction responsiveness by hydrating only small interactive parts.
import { h } from 'preact'; import Counter from '../islands/Counter.tsx'; export default function Page() { return ( <div> <h1>Welcome</h1> <Counter /> <p>Static content here...</p> </div> ); } // islands/Counter.tsx import { useState } from 'preact/hooks'; export default function Counter() { const [count, setCount] = useState(0); return <button onClick={() => setCount(count + 1)}>Count: {count}</button>; }
import { h } from 'preact'; import { useState } from 'preact/hooks'; export default function Page() { const [count, setCount] = useState(0); return ( <div> <h1>Welcome</h1> <button onClick={() => setCount(count + 1)}>Count: {count}</button> <p>Static content here...</p> </div> ); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full page hydration | High (all nodes hydrated) | Multiple reflows due to JS execution | High paint cost from layout thrashing | [X] Bad |
| Islands architecture | Low (only interactive islands) | Single reflow per island | Lower paint cost, smoother rendering | [OK] Good |
ISLAND tag to mark interactive components.ISLAND tag wraps the component, so it needs opening and closing tags.export default function Page() {
return (
<main>
<h1>Welcome</h1>
<ISLAND><Counter /></ISLAND>
<p>Static text</p>
</main>
);
}Counter component is wrapped inside the ISLAND tag, marking it interactive.export default function Page() {
return (
<main>
<ISLAND><Button /></ISLAND>
<ISLAND><Button /></ISLAND>
</main>
);
}ISLAND allows independent hydration, improving performance by loading only needed parts.Pass the test and this pattern moves unknown