Profile
Back to NewsBack
GitHub Trending 9 min
Reader Mode
11ty/is-land: A new performance-focused way to add interactive client-side components to your web site.

11ty/is-land: A new performance-focused way to add interactive client-side components to your web site.

4 hours ago

A new performance-focused way to add interactive client-side components to your web site.

Or, more technically: a framework independent partial hydration islands architecture implementation.

Features:
  • Easy to add to existing components
  • Zero dependencies
  • Not tightly coupled to a server framework or site generator tool.
  • Small footprint (1.79 kB compressed)
  • Server-rendered (SSR) component examples available for SSR-friendly frameworks (Lit, Svelte, Vue, Preact are provided)
Examples for: Integrations in the wild: Eleventy, WebC, Slinkity, SvelteKit, Bridgetown, Lit

Installation

Available on npm at @11ty/is-land.

npm install @11ty/is-land
<script type="module" src="/is-land.js"></script>

Add is-land.js to your primary bundle.

It can be deferred and/or loaded asynchronously. When using with web components it must be loaded before any other custom elements (via customElements.define) on the page. Choose your style:

Usage

<is-land>This is an island.</is-land>

Add any number of loading conditions to this tag to control how and when the island is initialized. You can mix and match. _All_ conditions be satisfied to initialize.

  • on:visible
  • on:load (new in v5)
  • on:idle
  • on:interaction (defaults to touchstart,click)
* Change events with on:interaction="mouseenter,focusin"
  • on:media
* When Viewport size matches: on:media="(min-width: 64em)" * Reduced motion: * When user prefers reduced motion on:media="(prefers-reduced-motion)" * When user has no preference on motion on:media="(prefers-reduced-motion: no-preference)" * When Save Data is active on:save-data * When Save Data is inactive on:save-data="false"
<is-land on:visible on:idle>
  <!-- your HTML here -->

<is-land on:media="(min-width: 64em)"> <!-- Islands can be nested --> <!-- Islands inherit all of their parents’ loading conditions --> </is-land> </is-land>

Programmatic API

Each loading condition is also available as a promise-returning method on Island.

await Island.onidle();
await Island.onvisible(element);
await Island.onload();
await Island.oninteraction(element); // or Island.oninteraction(element, "mouseenter,focusin")
await Island.onmedia("(min-width: 64em)");
await Island.onsavedata(); // or Island.onsavedata("false")

Controlling Fallback Content

Pre-JS

<is-land on:visible on:idle>
  <vanilla-web-component>
    Put your pre-JS fallback content in your web component.
  </vanilla-web-component>
</is-land>

Post-JS with