• Stars
    star
    351
  • Rank 120,906 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

<is-land>

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 (5 kB minimized; 1.61 kB with Brotli compression)
  • Server-rendered (SSR) component examples available for SSR-friendly frameworks (Lit, Svelte, Vue, Preact are provided)

Examples for:

Integrations in the wild:

Installation

npm install @11ty/is-land

Add is-land.js to your primary bundle. It can be deferred and/or loaded asynchronously.

When using with web components it must be the first custom element defined (via customElements.define) on the page. Choose your style:

<script type="module" src="/is-land.js"></script>
<script type="module">
import "/is-land.js";
</script>

The framework autoinit examples shown below now require a separate is-land-autoinit.js file too.

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:

  • on:visible
  • on:idle
  • on:interaction (defaults to touchstart,click)
    • Change events with on:interaction="mouseenter,focusin"
  • on:media
    • Viewport size: on:media="(min-width: 64em)"
    • Reduced motion:
      • Opt-in with on:media="(prefers-reduced-motion)"
      • Opt-out with on:media="(prefers-reduced-motion: no-preference)"
  • Save Data (read about Save Data on MDN)
    • Opt-in with on:save-data
    • Opt-out with 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>

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 <template>

Place any post-JS content inside of one or more <template data-island> elements anywhere in the <is-land>. These will be swapped with their template content. You can nest an <is-land> in there if you want!

<is-land on:visible on:idle>
  <template data-island>
    <vanilla-web-component>
      This component is post-JS.
    </vanilla-web-component>
  </template>
</is-land>
  • Use data-island="replace" to replace the contents of the <is-land> with the template.
  • Use data-island="once" to run a template’s contents once per page (keyed from template contents). (New in v2.0.1)

Run your own custom JavaScript, load your own CSS

Embed a script inside the template to run custom JS when the island’s loading conditions have been satisfied!

<is-land on:visible>
  <template data-island>
    <!-- CSS -->
    <style>/* My custom CSS */</style>
    <link rel="stylesheet" href="my-css-file.css">

    <!-- JS -->
    <script type="module">console.log("Hydrating!");</script>
    <script type="module" src="my-js-file.js"></script>
  </template>
</is-land>

You can also use the ready attribute for styling, added to the <is-land> when the island has been hydrated.

<style>
is-land[ready] {
  background-color: lightgreen;
}
</style>

Framework Support

Demos and source in the HTML are available for each framework listed here. These examples require the is-land-autoinit.js JavaScript file (in addition to is-land.js).

autoinit

Use the autoinit and import attributes together to import a third party library (or component code). autoinit can be one of petite-vue, vue, preact, or svelte. It is recommended to use a self-hosted framework library (future Eleventy integrations will automate this for you).

<is-land on:visible autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" v-scope="{ name: 'post-JS' }">
  Hello from <span v-html="name">pre-JS</span>
</is-land>

<!-- when import maps support is better, this simplifies with an entry for petite-vue in your import map -->
<is-land on:visible import="petite-vue" v-scope="{ name: 'post-JS' }">
  Hello from <span v-html="name">pre-JS</span>
</is-land>

Petite Vue

  • Small library (8K)
  • Rendering modes: Client
  • Progressive-enhancement friendly (full control of fallback content)
  • Support for autoinit
<is-land on:visible autoinit="petite-vue" import="https://unpkg.com/[email protected]/dist/petite-vue.es.js" v-scope="{ name: 'post-JS' }">
  Hello from <span v-html="name">pre-JS</span>
</is-land>

Vue

  • Larger library (51 kB)
  • Rendering modes: Client-only, Server-only, Server + Client (Hydration)
  • Support for autoinit
<is-land on:visible>
  <div id="vue-app">
    Hello from <span v-html="name">pre-JS</span>
  </div>

  <template data-island>
    <script type="module">
    import { createApp } from "https://unpkg.com/[email protected]/dist/vue.esm-browser.prod.js";

    createApp({
      data: () => ({ name: "post-JS" })
    }).mount("#vue-app")
    </script>
  </template>
</is-land>

Svelte

  • Smaller library (12 kB)
  • Rendering modes: Client-only, Server-only, Server + Client (Hydration)
    • Requires a compiler for both client and server modes (tighter server coupling)
  • Support for autoinit

This example uses an Eleventy/Svelte integration to compile a Svelte component.

{% assign component = "./lib/svelte/my-component.svelte" | svelte %}
<is-land on:visible autoinit="svelte" import="{{ component.clientJsUrl }}"></is-land>
Example component code ./lib/svelte/my-component.svelte:
<script>
  // using export to allow overrides via props
  export let name = 'world';

  let count = 0;

  function handleClick() {
    count += 1;
  }
</script>

<style>
  h1 { color: red }
</style>

<h1>Hello {name}</h1>

<button on:click={handleClick}>
  Clicked {count} {count === 1 ? 'time' : 'times'}
</button>

Preact

  • Very small library (~5 kB)
  • Rendering modes: Client-only, Server-only, Server + Client (Hydration)
  • Support for autoinit

This example uses htm instead of JSX.

<is-land on:visible autoinit="preact" import="/lib/preact/preact-component.js"></is-land>
Example component code ./lib/preact/preact-component.js:
import { html, render } from 'https://unpkg.com/htm/preact/index.mjs?module'

function App (props) {
  return html`<p><strong>Hello ${props.name}!</strong></p>`;
}

export default function(el) {
  render(html`<${App} name="from Preact" />`, el);
}

Lit

  • Small library (~7 kB)
  • Rendering modes: Client-only, Server + Client (Hydration)
    • Note: Server-only is not supported: it requires Declarative Shadow DOM support to work without JS.
  • No support for autoinit
<is-land on:visible import="./lib/lit/lit-component.js">
  <lit-component name="Post-JS">Pre-JS Content</lit-web-component>
</is-land>
Example component code ./lib/lit/lit-component.js:
import {html, css, LitElement} from "https://cdn.jsdelivr.net/gh/lit/dist@2/core/lit-core.min.js";

customElements.define('lit-component', class extends LitElement {
  static properties = {
    name: {type: String},
  };

  render() {
    return html`<p>Hello, ${this.name || "Stranger"}!</p>`;
  }
});

Alpine.js

  • Smaller library (15 kB)
  • Rendering modes: Client-only
  • No autoinit but it is not needed (functionality included for-free by Alpine.js)
<is-land on:visible import="https://unpkg.com/alpinejs">
  <div x-data="{ count: 0 }">
    Hello from Alpine.js!

    <button @click="count++">⬆️</button> <button @click="count--">⬇️</button> <span x-text="count"></span>
  </div>
</is-land>

More Repositories

1

eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
JavaScript
16,829
star
2

webc

Single File Web Components
JavaScript
1,163
star
3

eleventy-base-blog

A starter repository for a blog web site using the Eleventy static site generator.
Nunjucks
990
star
4

11ty-website

Documentation site for the Eleventy static site generator.
JavaScript
414
star
5

eleventy-img

Utility to perform build-time image transformations.
JavaScript
385
star
6

eleventy-plugin-vue

Use Vue.js templates and Vue.js single file components in Eleventy.
JavaScript
188
star
7

eleventy-fetch

Utility to cache any remote asset: Image, Video, Web Font, CSS, JSON, etc
JavaScript
122
star
8

eleventy-plugin-syntaxhighlight

A pack of Eleventy plugins for syntax highlighting in Markdown, Liquid, and Nunjucks templates.
JavaScript
115
star
9

eleventy-plugin-webc

Adds support for WebC *.webc files to Eleventy
JavaScript
104
star
10

eleventy-plugin-vite

A plugin to use Vite with Eleventy
JavaScript
104
star
11

api-screenshot

A service to add web page screenshots to your Eleventy sites.
JavaScript
97
star
12

eleventy-navigation

A plugin for creating hierarchical navigation in Eleventy projects. Supports breadcrumbs too!
JavaScript
92
star
13

eleventy-dev-server

A minimal generic web-development web server.
JavaScript
86
star
14

eleventy-activity-feed

Create one centralized RSS feed for all of the content you create across the web (aggregates from Twitter, RSS, Atom, Mastodon, YouTube)
JavaScript
81
star
15

eleventy-plugin-rss

A pack of Eleventy plugins for generating an RSS feed.
JavaScript
78
star
16

demo-eleventy-serverless

Run Eleventy in a serverless function
JavaScript
58
star
17

eleventy-upgrade-help

Helper plugin when upgrading your Eleventy project to a new major version.
JavaScript
52
star
18

api-indieweb-avatar

Return an optimized avatar image from a domain name input.
JavaScript
50
star
19

eleventy-plugin-bundle

Little bundles of code, little bundles of joy.
JavaScript
48
star
20

eleventy-plugin-inclusive-language

A linter plugin to check for inclusive language in markdown files.
JavaScript
39
star
21

demo-eleventy-serverless-oauth

A demo project using OAuth to secure some of your Eleventy Serverless routes.
JavaScript
38
star
22

eleventy-base-webc

A minimalist bare-bones starter project using Eleventy and WebC.
JavaScript
36
star
23

eleventy-assets

Code-split your CSS in Eleventy.
JavaScript
30
star
24

11ty-community

29
star
25

api-opengraph-image

A service that returns an optimized OpenGraph Image from a domain name input.
JavaScript
24
star
26

api-sparkline

Service to return sparkline SVG images.
JavaScript
19
star
27

eleventy-plugin-directory-output

Group and sort Eleventy’s verbose output by directory (and show file size with benchmarks)
JavaScript
17
star
28

tugboat

A modern starter project using Eleventy and WebC.
HTML
17
star
29

eleventy-server-browsersync

An Eleventy server plugin to use Browsersync with Eleventy 2.0+.
JavaScript
13
star
30

demo-eleventy-edge

Liquid
12
star
31

giffleball

Giffleball is a web site for Gifs
HTML
12
star
32

eleventy-community

A repository for Eleventy community discussions.
10
star
33

demo-eleventy-img-netlify-cache

A demo to show how to re-use Eleventy Image’s disk cache across Netlify builds.
JavaScript
10
star
34

eleventy-utils

Lower level internal utilities to share amongst Eleventy packages
JavaScript
9
star
35

api-img

A runtime service to optimize hosted images.
JavaScript
8
star
36

api-explorer

A simple way to browse the different runtime services provided by Eleventy
Nunjucks
8
star
37

demo-webc-counter

A progressively enhanced server-rendered form-aware web component counter using WebC
JavaScript
8
star
38

demo-eleventy-js-front-matter

Demo of free-form JavaScript in front matter to populate the Data Cascade.
Nunjucks
8
star
39

eleventy-benchmark

Eleventy Benchmark Speed Regression Test
HTML
8
star
40

11ty-logo

11ty logo built for a browser.
JavaScript
7
star
41

eleventy-dependency-tree

Returns an unordered array of local paths to dependencies of a node JavaScript file (everything it or any of its dependencies require()s)
JavaScript
7
star
42

eleventy-plugin-img

A plugin to perform runtime image transformations.
JavaScript
6
star
43

eleventy-img-cloud

Run eleventy-img in the CLOUD ⛅️
JavaScript
6
star
44

eleventy-data-transistor-fm

An Eleventy data plugin to source transistor.fm episodes.
JavaScript
5
star
45

api-generator

Find the <meta name="generator"> for a web site
JavaScript
4
star
46

demo-webc-image-compare

Server rendered image comparison web components built using WebC
JavaScript
4
star
47

lodash-custom

A custom, focused build of lodash exclusively for use internally in Eleventy.
JavaScript
4
star
48

demo-webc-shadow-dom

Demo of rendering modes of WebC components: Shadow DOM versus HTML
JavaScript
3
star
49

eleventy-base-plugin

A starter project for a Plugin for the Eleventy static site generator.
JavaScript
3
star
50

eleventy-import-disqus

A manual process to import existing exported disqus.xml content into an eleventy blog.
JavaScript
2
star
51

.github

Special README repository
Shell
1
star
52

demo-eleventy-upgrade-help

A test project to demonstrate usage of the eleventy-upgrade-help plugin
JavaScript
1
star
53

eleventy-sample-jstl

An Eleventy sample project using JSTL files.
1
star
54

demo-eleventy-from-scratch-blog

Companion code to the “6 Minutes to Build a Blog from Scratch” tutorial
HTML
1
star