v0.9.031.5 kB gzipped0 dependencies

Reactive components in plain .html files

jq79 parses and mounts single-file components in the browser, at runtime. No compiler, no bundler, no virtual DOM — one script from a CDN and any static host is the whole stack.

counter.html
<script :setup="{ step = 1 }">
  let count = 0
  $: double = count * 2
</script>

<button @click="count = count + step">
  clicked {{ count }} times
</button>
<span :if="count > 0">double is {{ double }}</span>

<style scoped>
  button { font: 600 1rem system-ui; padding: .7em 1.2em; border: 0; border-radius: 99px; background: #3178c6; color: white; }
  span { font: 1rem system-ui; margin-left: .8em; }
</style>
Live result fetching counter.html…
Why jq79

The file you write is the file you ship

Most component frameworks need a toolchain between your source and the browser. jq79 moves that step into a 31.5 kB runtime, so the browser can take your components as they are.

No build step

Import the library from a CDN, fetch a component from your own host, mount it. That is the whole deployment.

index.html
<script type="module">
  import { C79 } from "https://esm.sh/jq79"
  C79.fetch("./app.html").mount("#app")
</script>

A component is one file

Markup, a setup script and styles side by side, in a .html file any editor, server or CDN already understands.

hello.html
<script :setup="{ name }"></script>

<h1>Hello {{ name }}!</h1>

<style scoped> h1 { color: tomato } </style>

Variables are state

Top-level let and const are reactive, and $: derives from them. No hooks, no signals to unwrap, no setState.

<script :setup>
  let price = 4
  let quantity = 2
  $: total = price * quantity
</script>

Fine-grained updates

Proxies track what each binding read. A write re-runs only those bindings — no diffing, no re-rendering the component.

rows[3].label = "renamed"
// one text node changes; the other
// 999 rows aren't even looked at

Code splitting is the file system

An import() of an .html fetches that component when it's needed: the ones a script is sure to need start together, before its first line runs; one in a handler waits for its line. The chunk is the file; there's no chunk graph to configure.

const Chart = await import("./Chart.html")

Tooling when you want it

A dev server with hot reload, a Vite plugin, TypeScript in setup scripts, a VS Code extension, and a CSP-safe mode. All optional.

npx jq79 dev   # serve + hot reload
Guide

From an empty folder to an app

In the order you'll need it: install, put it on a page, write components, compose them, share state, load data, and ship.

01Install

Nothing to install if you don't want to: every major CDN serves the package. Pin a version in production.

from a CDN, as a module
<script type="module">
  import { C79 } from "https://esm.sh/jq79"
  // or https://cdn.jsdelivr.net/npm/jq79/+esm
</script>
or as a classic script
<script src="https://cdn.jsdelivr.net/npm/jq79/dist/jq79.global.js"></script>
<script>
  const { C79 } = jq79
</script>

With npm, for a bundler or the dev tools:

terminal
npm install jq79

02Put it on a page

C79.fetch() downloads a component and hands back a pending one you can mount straight away — every call queues on the download. The second argument is the component's props.

index.html
<!doctype html>
<main id="app"></main>

<script type="module">
  import { C79 } from "https://esm.sh/jq79"

  C79.fetch("./app.html").mount("#app", { title: "Today" })
</script>

Awaiting it gives you the component itself; fetchAll() loads several in parallel. Each URL is downloaded once and reused by later fetches and imports — Component79.cache(false) turns that off.

const app = await C79.fetch("./app.html").mount("#app")
const [Header, Footer] = await C79.fetchAll(["./Header.html", "./Footer.html"])

03Write a component

Markup, an optional <script :setup> and an optional <style>, in any order.

app.html
<script :setup="{ title }">
  let todos = []
  let draft = ""

  $: left = todos.filter(todo => !todo.done).length

  const add = () => {
    todos = [...todos, { text: draft, done: false }]
    draft = ""
  }
</script>

<h1>{{ title }} <small>{{ left }} left</small></h1>

<form @submit.prevent="add">
  <input :value="draft" @input="draft = $event.target.value">
  <button :disabled="!draft">add</button>
</form>

<style scoped>
  small { color: gray; font-weight: normal; }
</style>
  • :setup="{ title }" declares the props the component takes, with optional defaults.
  • Top-level let/const become reactive; assigning to them — from a handler, a timer or a .then() — updates the DOM.
  • $: re-runs whenever what it reads changes.
  • scoped keeps the styles inside this component.

04Templates: bind, branch, loop

Expressions in {{ }}, attributes with :name, events with @name, structure with :if and :each.

<ul>
  <li :each="todo in todos" :key="todo.id" :class.done="todo.done">
    <input type="checkbox" :checked="todo.done"
           @change="todo.done = $event.target.checked">
    {{ todo.text }}
  </li>
</ul>

<p :if="!todos.length">Nothing to do.</p>
<p :elseif="left === 0">All done 🎉</p>
<p :else>{{ left }} to go</p>

<a :href="`/todos/${id}`" @click.prevent="open(id)">details</a>

Event modifiers (.prevent, .stop, .once…), :class as string/object/array, :html with a sanitizer, :with to narrow scope.

05Compose components

Import a component in the setup script and use it as a tag. Props go down, $emit events come up, and :model wires both ways.

TodoList.html
<script :setup>
  const TodoItem = await import("./TodoItem.html")

  let todos = [{ id: 1, text: "write a component" }]
  const remove = todo => { todos = todos.filter(t => t !== todo) }
</script>

<ul>
  <TodoItem :each="todo in todos" :key="todo.id"
            :todo @remove="remove(todo)" />
</ul>
TodoItem.html
<script :setup="{ todo }"></script>

<li>
  {{ todo.text }}
  <button @click="$emit('remove')">×</button>
</li>

Slots pass markup instead of data, and several components can live in one file with <template name>.

<Card>
  <template :slot.header><h2>{{ title }}</h2></template>
  <p>{{ body }}</p>
</Card>

06Stores & services

When two components need the same state, make it a store. $reactive works anywhere — including a plain module, which is all an app-wide service needs to be. $computed derives from it.

cart.js
import { $reactive, $computed } from "https://esm.sh/jq79"

export const cart = $reactive({ items: [] })

export const total = $computed(() =>
  cart.items.reduce((sum, item) => sum + item.price, 0)
)

export const add = item => { cart.items = [...cart.items, item] }
CartBadge.html
<script :setup>
  const { cart, total } = await import("./cart.js")
</script>

<span>{{ cart.items.length }} items · {{ total.value }} €</span>

Every component that holds the store sees every write, whoever made it. A store passed as a prop is shared the same way — no context API, no injection.

07Data & the DOM

A setup script can await. The template waits for it — or renders straight away from await $mounted(), and fills in when the data lands. After it, the component's DOM is there to query with $self.

Users.html
<script :setup>
  let users = []
  let loading = true

  await $mounted()            // render now, fill in later
  $self("input").focus()

  users = await fetch("/api/users").then(r => r.json())
  loading = false
</script>

<input placeholder="search">
<p :if="loading">loading…</p>
<ul :else>
  <li :each="user in users" :key="user.id">{{ user.name }}</li>
</ul>

08Develop

No bundler: npx jq79 dev serves your folder as-is and hot-reloads the components you edit, keeping their state.

terminal
npx jq79 dev            # http://localhost:4179

With Vite: the plugin imports .html components as modules, with HMR and TypeScript in setup scripts. The same files keep working when fetched at runtime.

vite.config.js
import { jq79 } from "jq79/vite"

export default { plugins: [jq79()] }
main.js
import App from "./App.html"

App.mount("#app")

In your editor: the VS Code extension highlights and type-checks components; jq79-check does the same in CI.

09Ship

Upload the folder to any static host — GitHub Pages, S3, a CDN. There's no build output because there's no build. For a page with a strict Content Security Policy, safeEval runs without 'unsafe-eval', with or without a bundler.

import { C79 } from "https://esm.sh/jq79@0.9.0"   // pin it

await C79.safeEval()        // no new Function, ever
C79.fetch("./app.html").mount("#app")
Tutorial

Learn it by doing, in the browser

22 short lessons, each a component you edit with a live preview beside it. Because there is no compiler, the tutorial runs the real library: the component you write is the component that mounts.

Open the tutorial →
  1. Getting started
    Your first component · No build step
  2. Templates
    Reactive state · Lists and conditions · Attributes · Forms and narrowed scope · Keys and identity · Objects and entries · Untrusted HTML
  3. Components
    Nested components · Component events · Two-way binding · Spreading props · Slots — passing markup, not just data · Several components in one file · Scoped styles
  4. State
    Shared state · Keeping state out of the store
  5. Data and the dom
    Loading data · Loading on demand · Reaching the DOM · Factory scripts
By the numbers

Small, tested, measured

31.5 kBgzipped, the whole runtime
0runtime dependencies
98%line coverage
22tested tutorial lessons

Updates are where jq79 is fastest: a write reaches only the bindings that read the path it changed, so updating rows in a 10,000-row table costs what the changed rows cost. Every release is measured on the js-framework-benchmark row table, against itself and against React, Vue, Svelte and Preact.

See the benchmark →

One file. No build. Go.

Paste the page from step 02 into a folder, add an app.html, and open it.