docs

CrootJS Coding Conventions

These rules are mandatory for any code built with CrootJS — whether written by hand or generated by an AI coding agent (Claude Code, Cursor, Copilot, etc). They apply to CrootJS’s own repos (lib, docs, examples, crootjs.github.io) and to any project that imports CrootJS.

1. Separate HTML, CSS, and JS into their own files

A page should look like this:

<!-- index.html -->
<link rel="stylesheet" href="style.css">
...
<button class="copy-btn">Copy</button>
...
<script type="module" src="script.js"></script>
// script.js
document.querySelectorAll('.copy-btn').forEach(btn => {
    btn.addEventListener('click', () => { /* ... */ });
});

Not like this:

<!-- don't -->
<style> .copy-btn { ... } </style>
<button style="color: blue" onclick="doThing()">Copy</button>
<script> function doThing() { ... } </script>

One exception: loading a third-party library from its own CDN (e.g. Lucide icons, SweetAlert2) via a plain <script src="..."> tag is fine — that’s an external dependency, not inline application logic.

2. JavaScript must be loaded as an ES module

Every .js file your page owns must be loaded with type="module":

<script type="module" src="script.js"></script>

Never as a plain classic script. This matches how CrootJS itself is distributed (import { x } from "https://cdn.jsdelivr.net/gh/crootjs/lib@<version>/module.js") and keeps the whole page in strict-mode ES module scope — no accidental globals.

3. Import CrootJS from a pinned CDN version

import { getJSON, postJSON } from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.13/api.js";

Why

For AI coding agents

If you (an AI agent) are building or editing a page that uses CrootJS, drop CLAUDE.md into the project root — Claude Code (and compatible agents that read a root instructions file) will pick these rules up automatically:

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

Read it in a browser at croot.js.org/lib/CLAUDE.