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
- No inline
<style>blocks in HTML. CSS lives in its own.cssfile, linked with<link rel="stylesheet" href="...">. - No inline
<script>blocks with logic in HTML. JS lives in its own.jsfile. - No inline
style="..."attributes. Use a class name and define the rule in the CSS file. - No inline event handler attributes (
onclick="...",onchange="...",oninput="...", etc). Attach listeners in JS withaddEventListener(or CrootJS’sonClick/onChange/onInputhelpers fromelement.js).
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.
One exception: integrity.js, the file that installs the import map with SRI hashes for CrootJS modules, is a classic script (<script src="integrity.js"></script>), the first script in <head>. An import map must exist before any module starts loading; Firefox ignores one added later, so a module can’t install it, and an inline <script type="importmap"> would break rule 1. The file holds only the import map, no other logic.
3. Import CrootJS from a pinned CDN version
import { getJSON, postJSON } from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/api.js";
- Always pin an exact version tag (
@0.0.5), never@latest, in committed code —@latestcan silently change behavior under you. - Import only the specific module files you actually use (
cookie.js,url.js, …), not the whole library, so the page only loads what it needs. - In production use
.min.js(api.min.js) for every CrootJS import on the page, all from the same version. Never mixapi.min.jswithstorage.js: they are different module URLs, so a module imported by both is loaded twice and each copy keeps its own state. Since 0.0.38 the.min.jsfiles in a release import the.min.jsof their sibling modules. - To make the browser reject a file whose content changed behind the same URL, add
integrityhashes (SRI) and bump versions withtools/bump-pins.py, which updates the hashes too.
4. No AI slop
Code generated by an AI agent must be as deliberate as hand-written code. These rules are checked in review; breaking one is a reason to reject the change.
- Never invent an API. Before calling any CrootJS function, check its name, parameter order, and options against llms.txt or the module’s docs page for the pinned version. If what you need does not exist, write it explicitly in your own code — don’t guess an option and hope.
- Use what CrootJS already has.
api.jsfor requests,element.jsfor DOM by ID,router.jsfor page routing,table.jsfor data tables,chart.jsfor charts,markdown.jsfor Markdown,qr.jsfor QR codes,openapi.jsfor API documentation,map.jsfor maps,model3d.jsfor 3D,toast.jsfor notifications,croot.cssandicons.cssfor styling and icons. Don’t re-implement them, and don’t add a library that duplicates them (Leaflet, Three.js, axios, jQuery, DataTables, Chart.js, marked, Swagger UI, js-yaml, Bootstrap/Bulma, icon fonts). - No dead weight. No unused imports, variables, or functions; no commented-out code; no
TODO/placeholder stubs; no “example” functions nobody calls; no files that aren’t needed. - Comments explain why, not what. Don’t narrate each line (
// get the value,// import CrootJS). Comment the reason behind a non-obvious choice, in the same language as the rest of the project. - No fake content. No lorem ipsum in finished pages, no invented statistics, testimonials, or claims (“trusted by thousands of developers”). Sample data is labelled as sample data.
- Handle errors that can actually happen. Follow each function’s contract (e.g.
api.jsreports network failure asstatus: 0); don’t wrap everything intry/catchthat swallows errors, and don’t add checks for states that cannot occur. - Stay in scope. Change only what the task needs. Don’t rename, reformat, or restyle unrelated code; don’t “improve” things nobody asked about.
- Real HTML, not div soup. Buttons are
<button>, inputs have<label>s, everything works with the keyboard and at phone width. No decoration that wasn’t asked for (gradients, emoji, animations; see No “AI look”). - Verify before saying “done”. Open the page through a local server, check the browser console has no errors, and try the feature — including at phone width and with touch if it’s interactive. Say plainly what you did not test.
- Pin and minimise dependencies. Exact version tags only (never
@latest), and only the modules the page uses.
Quick check before handing work back: Does every CrootJS call exist as written? Is every line used? Did I run it? Did I change anything I wasn’t asked to?
5. No “AI look”
Pages generated by AI tend to look the same, and people notice. A CrootJS page should look like it was made for its users, not like a template. Start from croot.css, the optional ui.css components, a themes.css theme, and the page patterns, and change them only where the product needs it.
| Don’t | Do instead |
|---|---|
| Purple/indigo-to-blue gradients, gradient text in headings | One accent color from the theme (--croot-accent), used sparingly for links, the primary button, and the current item |
Glassmorphism (backdrop-filter: blur), glows, floating blobs |
Plain surfaces (--croot-surface) separated by borders (--croot-border) and whitespace |
| Shadows and big rounded corners on every card | The theme’s --croot-radius; a shadow only on things that float (dialogs, menus) |
| Emoji as icons, icons in colored circles | icons.css icons next to text, or no icon at all |
| Three identical feature cards with an icon, a title, and two lines | A short list or a table that says what the product does; real screenshots, labelled |
| Web fonts like Inter or Poppins by default | The system font stack from croot.css, or a theme’s heading font |
| Hero sections with a slogan and two buttons on every page | Put the task first: a back-office page opens on its data, a form on its first field |
| Marketing copy (“seamless”, “blazing fast”, “trusted by thousands”) | Plain sentences about what the page does; no invented numbers or testimonials |
| Animations on scroll, hover lifts, spinning loaders | .skeleton while loading, and motion only where it explains a change (respect prefers-reduced-motion) |
| Colour as the only signal (red/green badges) | Text plus colour: “Naik 4%”, “Gagal”, aria-current, icons with labels |
Check before handing back: Would this page look out of place next to the CrootJS docs and examples? Could you tell which tool generated it? If yes, remove the decoration until it can’t.
6. A 404.html next to every index.html
Every site (the folder that holds the site’s index.html, usually the repo root on GitHub Pages) must also have a 404.html in the same folder. GitHub Pages and most static hosts show it for every address that doesn’t exist in that site, instead of their own generic error page.
- Same rules as any page: its own CSS file (or croot.css), no inline styles or scripts, works at phone width and in dark mode.
- Say plainly that the page doesn’t exist and link to the places people most likely wanted (home, docs, search or list pages). No jokes that hide the message, no redirect that loses the wrong address.
- Use absolute paths (
/style.css,/) for its CSS and links: the same404.htmlis shown for wrong addresses in every subfolder. - Add
<meta name="robots" content="noindex">so search engines don’t index it. -
A copy-ready example is in the page patterns.
- Maintainable: a reviewer (human or AI) can look at one file at a time instead of untangling markup, styling, and behavior mashed together.
- Cacheable: separate
.css/.jsfiles are cached by the browser independently of the HTML that changes more often. - No build step required: this works with plain
<link>/<script type="module">tags — no bundler needed, consistent with CrootJS’s zero-install philosophy. - AI-agent friendly: a coding agent generating or editing a CrootJS page has one unambiguous place to put each kind of code, instead of guessing whether to inline it.
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.