Tools for building Offline-first Web Apps
README.md

Building Inro apps #

Guides for building an Inro app — an offline-first, installable PWA that ships like software rather than deploying like pages.

An Inro app is a static bundle — HTML, an ES-module entry point, a service worker, and CSS — that inro build emits from a www/ source tree. No server-side rendering, no backend to run, and controlled versioning: users keep the version they committed to until they choose to update.

Protocol-level design lives in the specs under docs/spec/; per-symbol API docs are generated at https://jsr.io/@inro/<package>/doc.


Quickstart #

1. Prerequisites #

# Deno 2.x
curl -fsSL https://deno.land/install.sh | sh

# The Inro CLI (installs the `inro` binary)
deno install jsr:@inro/cli -Afg --name=inro

inro icons (optional, for generating PWA icon sizes) shells out to ImageMagick — install it if you want icon generation, otherwise skip that step.

2. Scaffold and run #

inro init my-app                             # or: inro init my-app --url https://my-app.example
cd my-app
deno task init                               # inro icons — generate icon sizes (needs ImageMagick; optional)
deno task dev                                # inro start — dev server at http://localhost:8000, live rebuild

inro init copies the template into my-app/ — an inro.json build config, a deno.json, and a www/ tree with a working router, service worker, and example routes. deno task dev serves it and rebuilds on every save (--port 3000 to change the port). That's already an installable, offline-first PWA — no server involved.

3. Build and deploy #

deno task build                              # inro build → static bundle in inro.json "outdir" (e.g. ./www/dist)

inro build produces a version-namespaced JS bundle, the service worker, the web manifest, and generated icons. There's no server component, so deploying is a drag-and-drop:

  • Netlify Drop or Cloudflare Pages Direct Upload — drag the output folder in and you have a live HTTPS PWA.
  • Deno Deploy / GitHub Pages / any static host — point it at the output directory.
  • Your own box — serve the directory behind Caddy or nginx.

Two things to get right on any host but inro start: one response header on the service worker's versioned route, and an additive deploy — publish each new build alongside the old version directories rather than replacing them, or installs pinned to an older version stop loading entirely. See Deployment for ready-to-use snippets and the reasoning.


The shape of an app #

inro init scaffolds this tree:

my-app/
├── inro.json              ← build config (name, type, root, outdir, static, icon)
├── deno.json              ← imports (@inro/*, lit) + tasks (dev/build/icons)
└── www/
    ├── index.html         ← <header>, <main>, optional <footer>/<ui-bottom-bar>
    ├── index.ts           ← entry: router + client.init()
    ├── worker.ts          ← service worker: init([...plugins])
    ├── routes/*.ts        ← one LitElement custom-element per page
    └── static/            ← inro.css, theme.css, app.css, icons

Two conventions hold every app together.

A route is a custom element #

Routes are plain Lit elements rendered into the light DOM (createRenderRoot() { return this }) so they inherit the app's global CSS instead of being isolated by shadow DOM:

// www/routes/home.ts
import { html, LitElement } from 'lit'

class HomePage extends LitElement {
  override createRenderRoot() {
    return this // light DOM: inro.css / theme.css apply
  }
  override render() {
    return html`<ui-card>Hello.</ui-card>`
  }
}
customElements.define('home-page', HomePage)

Wire routes together with createLayoutRouter from @inro/ui, which swaps one element into a <main> landmark per route and manages headers and nav:

// www/index.ts
import { createLayoutRouter } from '@inro/ui'
import { client } from '@inro/workers'
import './routes/home.ts'
import './routes/about.ts'

client.init()

const { ready } = createLayoutRouter<NavMeta>({
  router: { selectorAttrib: 'data-route', useHash: true },
  defaultRoute: '/',
  landmarks: { main: 'main', header: 'body > header' },
  routes: {
    '/': { main: () => ({ tag: 'home-page' }) },
    '/about': { main: () => ({ tag: 'about-page' }) },
  },
})
ready()

Hash routing (useHash: true) means deep links need no server rewrite rules — that's what makes the drag-and-drop deploy work. The UI guide covers the router, the ui-* components, and styling.

A service worker precaches the shell #

www/worker.ts makes the PWA open with no network:

// www/worker.ts
import {
  init,
  versionedUrl,
  withCleanup,
  withFetchStrategy,
  withPrecache,
  withUpdatePolling,
} from '@inro/workers'

init([
  withPrecache([
    '/',
    '/index.html',
    versionedUrl('/dist/index.js'),
    '/manifest.json',
    '/static/theme.css',
  ]),
  withCleanup(),
  withUpdatePolling(),
  withFetchStrategy(),
])

inro build writes the bundle to a fresh version-namespaced directory every build; versionedUrl resolves /dist/index.js to that build's actual path, which is what makes updates reliable no matter how a host caches static files.

On the client side (index.ts), @inro/workers exposes client: client.init() registers the worker, client.startUpdatePolling() prompts on a new version, and client.applyUpdate() is there if you build your own update UI. For the standard update prompt, drop <ui-version> (@inro/ui) into the app shell — it checks for and applies updates with no further wiring.


Adding a data layer #

Inro owns the app shell; state is yours. For a reactive, versioned document store — plus cross-device sync, E2E encryption, sharing, and AI services — add Civility: its guides (civility/docs/apps/) pick up exactly where this page leaves off, and its civ-* components drop into the same layouts and cascade layers.

Features #

  • UI — the layout router, ui-* web components, and the CSS / theming system.
  • Deployment — the one response header your static host must set, and why deploys are additive.

Standalone HTML demos of the UI components live in examples/.