Islands architecture helps build fast web pages by only loading small interactive parts instead of the whole page. This makes websites quicker and easier to use.
Islands architecture in Fresh in Deno
import { useState } from "preact/hooks"; export const handler = { async GET(req, ctx) { return ctx.render(); }, }; export const Counter = () => { const [count, setCount] = useState(0); return ( <button onClick={() => setCount(count + 1)}> Count: {count} </button> ); }; export default function Page() { return ( <div> <Counter /> </div> ); }
Islands are small interactive components inside mostly static pages.
Components using useState or event handlers like onClick are automatically islands.
import { useState } from "preact/hooks"; const Button = () => { const [clicked, setClicked] = useState(false); return <button onClick={() => setClicked(true)}>{clicked ? "Clicked!" : "Click me"}</button>; };
export default function Page() {
return (
<main>
<Greeting name="Alice" />
</main>
);
}
const Greeting = ({ name }) => {
return <p>Hello, {name}!</p>;
};This is a complete Fresh page using islands architecture. The page shows a heading and a button that updates its count when clicked. Only the button is interactive and runs JavaScript on the client, making the page fast and accessible.
import { useState } from "preact/hooks"; export const handler = { async GET(req, ctx) { return ctx.render(); }, }; const Counter = () => { const [count, setCount] = useState(0); return ( <button onClick={() => setCount(count + 1)} aria-label="Increment count"> Count: {count} </button> ); }; export default function Home() { return ( <main> <h1>Welcome to Fresh Islands</h1> <Counter /> </main> ); }
Islands run JavaScript only where needed, improving performance.
Use semantic HTML and ARIA labels inside islands for accessibility.
Islands can receive props to customize their behavior.
Islands architecture splits pages into static and interactive parts.
Components with client-side JavaScript like useState are automatically islands in Fresh.
This approach makes web pages faster and easier to maintain.
Practice
Solution
Step 1: Understand Islands architecture concept
Islands architecture divides a web page into static parts and small interactive components called islands.Step 2: Identify the main benefit
This split improves page speed and maintainability by only hydrating interactive parts.Final Answer:
To split pages into static and interactive parts for better performance -> Option AQuick Check:
Islands architecture = split static + interactive [OK]
- Thinking all page parts are interactive
- Believing Islands disables JavaScript
- Assuming full client-side rendering
Solution
Step 1: Recall correct tag casing
Fresh uses uppercaseISLANDtag to mark interactive components.Step 2: Check tag usage
TheISLANDtag wraps the component, so it needs opening and closing tags.Final Answer:
<ISLAND>MyComponent</ISLAND> -> Option AQuick Check:
Correct tag is uppercase ISLAND with open/close [OK]
- Using lowercase or mixed case tags
- Using self-closing without children
- Confusing with other component tags
export default function Page() {
return (
<main>
<h1>Welcome</h1>
<ISLAND><Counter /></ISLAND>
<p>Static text</p>
</main>
);
}Solution
Step 1: Identify ISLAND usage
TheCountercomponent is wrapped inside theISLANDtag, marking it interactive.Step 2: Understand static vs interactive parts
The heading and paragraph are outside ISLAND, so they remain static and non-interactive.Final Answer:
Only the Counter component inside the ISLAND tag is interactive -> Option CQuick Check:
ISLAND wraps interactive parts only [OK]
- Assuming whole page is interactive
- Thinking ISLAND tag is invalid
- Believing static parts become interactive
export default function Page() {
return (
<main>
<ISLAND><Button /></ISLAND>
<ISLAND><Button /></ISLAND>
</main>
);
}Solution
Step 1: Analyze multiple ISLAND usage
Using the same interactive component multiple times inside separate ISLAND tags can cause hydration conflicts if keys are missing.Step 2: Understand hydration uniqueness
Each island needs a unique key or identifier to avoid duplicate hydration errors.Final Answer:
Using multiple ISLAND tags with the same component can cause duplicate hydration issues -> Option BQuick Check:
Duplicate islands need unique keys to avoid errors [OK]
- Thinking ISLAND tags must be self-closing
- Believing components can't be inside ISLAND
- Assuming ISLAND wraps only HTML elements
Solution
Step 1: Understand hydration granularity
Wrapping each button in its ownISLANDallows independent hydration, improving performance by loading only needed parts.Step 2: Importance of unique keys
Assigning unique keys to each island prevents hydration conflicts and ensures smooth interactivity.Final Answer:
Wrap each button in its own <ISLAND> with unique keys to hydrate only needed parts -> Option DQuick Check:
Separate islands with keys = better performance [OK]
- Grouping all buttons in one island causing unnecessary hydration
- Not using ISLAND tags and hydrating whole page
- Misusing ISLAND on static content
Ready to prove it?
Pass the test and this pattern moves unknown
