Vanilla JavaScript modules for static sites, straight from a CDN

Fetch and DOM helpers, form validation, tables, charts, maps without Leaflet, a 3D viewer without Three.js, and a small CSS framework. Every module is one file on jsDelivr: import only what the page uses. No npm install, no bundler.

Releases jsDelivr hits per month GPL-2.0

Documentation Examples Source on GitHub

index.js
import { getJSON } from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/api.min.js";
import { createTable } from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/table.min.js";

const { status, data } = await getJSON("https://api.example.com/students");
if (status === 200) {
    createTable("students", {
        columns: [{ key: "nim", label: "NIM" }, { key: "name", label: "Name" }],
        rows: data,
    });
} else if (status === 0) {
    // the server never answered: offline, timeout, or CORS
}

What's in it

Pages and data

api.js
getJSON, postJSON, putJSON, deleteJSON by callback or await, with headers, timeout, cancellation, and a localStorage cache that can serve stale data when the API is down; uploadFile with progress and downloadFile. Network failure is status: 0, never an exception.
element.js, form.js
DOM helpers by element ID (onClick, setInner, getValue, serializeForm, fillForm) and form validation with a message under each field that screen readers announce.
router.js, table.js, chart.js
What dashboards used jQuery, DataTables and Chart.js for: a single-page router, data tables with sorting, search, pages and a server mode, and SVG bar, line and donut charts.
openapi.js
API documentation from an openapi.yaml, with ready-to-copy CrootJS code and a try-it button per operation. About 11 KB gzipped, instead of Swagger UI's 460 KB.
markdown.js, qr.js, toast.js
Markdown to HTML that is safe by design (raw HTML escaped, javascript: links refused), QR codes as SVG, and notifications that screen readers announce.
cookie.js, storage.js, url.js, validate.js
Session cookies, localStorage with expiry, query strings, and input checks.

Look

croot.css
Plain HTML looks finished without classes: forms, buttons, tables, dialogs, dark mode. About 2 KB gzipped, no web fonts, in a CSS layer so your own styles always win.
ui.css, themes.css, icons.css
Optional extras for apps: a sidebar shell, tabs, menus, accordion, steps and switches (about 3 KB), four themes, and 49 icons. Start from the page patterns instead of a generated template.

Maps and 3D

map.js and its add-ons
A slippy map written from scratch (about 13 KB gzipped): GeoJSON as SVG, markers, drawing, address search, offline basemaps from PMTiles, clustering, heatmaps and coverage grids, measuring, and shortest routes computed in the browser.
model3d.js, model3dtools.js
A glTF/GLB viewer on WebGL (about 16 KB gzipped) with Draco support, part picking and recoloring, labels, gizmos, animation, exploded views, cross-sections, measuring, AR, and GLB export.

Login and offline

auth.js, stp.js
A WhatsAuth QR-code and OTP login flow with Google Sign-In, without third-party scripts.
pwa.js, serviceworker.js
Make an app installable and keep it opening without internet, with a notice when a new version is ready.

Getting started

  1. Link croot.min.css and your own style.css, and load your script as a module: <script type="module" src="index.js">. HTML, CSS and JS stay in separate files.
  2. Import the modules you use from a pinned version, as .min.js in production, never mixed with .js. Add <link rel="modulepreload"> for them and the modules they import (list). To have the browser reject a file whose content changed, add SRI hashes, and bump versions and hashes together with bump-pins.py.
  3. Put a 404.html next to index.html, and check the page at phone width and in dark mode. The full rules are in the conventions.

Building with an AI coding agent

Drop CLAUDE.md into your project root. Claude Code, and other agents that read a root instructions file, then follow the CrootJS rules: separate files, pinned imports, no invented APIs, and no "AI look".

terminal
curl -o CLAUDE.md https://raw.githubusercontent.com/crootjs/lib/main/CLAUDE.md

Agents that read docs instead of guessing can start from llms.txt (every module and signature on one page), llms-full.txt (all module docs in one file), or any doc page as plain Markdown, such as /docs/map.md. Read CLAUDE.md.

Examples

Working pages with their source. Copy one and change what your project needs. All examples.

Formerly JSCroot

CrootJS is the successor of JSCroot: the same modules, continued in crootjs/lib. The old site jscroot.github.io and the jscroot repos now redirect here. Pages that still load jscroot/lib from jsDelivr keep working, but get no more fixes. See the migration guide (panduan migrasi).

Questions

Do I need npm or a build step?

No. Each module is an ES module file on jsDelivr, imported with a full URL from a <script type="module">. Modules have no runtime dependencies; the few that need something heavy (the Draco decoder for compressed 3D models) download it only when it is used.

Which version should I use?

Pin an exact tag, such as @0.0.41, and update it on purpose. Not @latest, which changes under you, and not a commit SHA from main, which lacks the built .min.js files. Changes per version are in the changelog.

Can I use only part of it?

Yes, that is the point: import api.min.js alone, or only link croot.min.css. A page downloads exactly the files it names, plus the few modules those import.

My project uses JSCroot. What changes?

The import URLs, and a few functions that were removed or renamed. The migration guide lists them with their replacements.