Human in The Loop Documentation

Bahasa Indonesia

Documentation for using CrootJS with an AI Companion and a human in the loop.

Coming from JSCroot? Read From JSCroot to CrootJS: new import URLs, removed functions and their replacements, and changed behavior.

Import every module from a pinned version, e.g. https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/api.min.js. In production use .min.js for every CrootJS import on a page, never mixed with .js: api.min.js and storage.js are different module URLs, so a module imported by both is loaded twice, each copy with its own state. Since 0.0.38 the .min.js files in every release import the .min.js of their sibling modules.

Pin to a tag (@0.0.39), not to a commit SHA from main. Our own .min.js files only exist in the release commits (on the dist branch, since 0.0.40); for a SHA from main, jsDelivr minifies on its own and its api.min.js imports "./storage.js" again.

Loading faster with modulepreload

A browser only learns that a module needs another one after it has downloaded it, so every level of imports adds one round trip to the server (about 150 ms on mobile networks). These modules import others:

Module Also loads Levels
api.js storage.js 1
auth.js cookie.js, api.js, storage.js, url.js, element.js, template.js, useragent.js, qr.js 2
config.js auth.js, cookie.js, api.js, storage.js, url.js, element.js, template.js, useragent.js, qr.js 3
form.js element.js 1
geomeasure.js geo.js 1
georoute.js geo.js, geomeasure.js 2
map.js geo.js 1
mapcluster.js geo.js 1
mapdraw.js geo.js 1
mapheat.js geo.js 1
mapmodel.js model3d.js 1
mapoffline.js mapvector.js 1
maptools.js geomeasure.js, geo.js 2

Add <link rel="modulepreload"> in <head> for the modules you import and the ones in the “Also loads” column, with the same version and .min.js suffix. They are then all downloaded together from the start. Example for a page that imports api.min.js:

<link rel="modulepreload" href="https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/api.min.js" integrity="sha384-FkrcJYDj82Td9axSh3O+A2TIpwCIg67PsrurLGMr5vk4KnL8c+zONZlBbaMEU0Cy">
<link rel="modulepreload" href="https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/storage.min.js" integrity="sha384-I68UpwZkgCfB4R68KBk7oSjwdRZqI+8zHf73gCvG+J2YFk5fxD3kBQjgt45dGk0Z">
<script type="module" src="index.js"></script>

On the croot.js.org landing page this moves the first API request about 300 ms earlier at 150 ms latency. The table above is generated from the code with python3 tools/module-deps.py in the lib repo.

The integrity attributes in the example are explained in the next section. python3 tools/module-deps.py <version> prints the modulepreload lines of every module with their hashes.

Locking file contents with integrity (SRI)

Pinning a version keeps the URL the same, not the content: what is behind @0.0.41 still depends on jsDelivr and GitHub. With an SRI (Subresource Integrity) hash the browser hashes the downloaded file and refuses to run it when the hash doesn’t match. Since 0.0.42 every release includes integrity.json (https://cdn.jsdelivr.net/gh/crootjs/lib@<version>/integrity.json): sha384 hashes of every .js, .min.js, .css, and (since 0.0.43) .min.css, plus the modules each module imports.

integrity on <link rel="modulepreload"> alone is not enough: only Chromium rejects a changed file, Firefox and Safari still run the module loaded by import. All three enforce an import map with an integrity key, and that import map also covers imports inside modules (api.min.js imports storage.min.js). Install it from integrity.js, the first script in <head> and a classic one (the only exception to the ES module rule):

<head>
  <script src="integrity.js"></script>
  <link rel="modulepreload" href="https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/api.min.js" integrity="sha384-FkrcJYDj82Td9axSh3O+A2TIpwCIg67PsrurLGMr5vk4KnL8c+zONZlBbaMEU0Cy">
  <link rel="modulepreload" href="https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/storage.min.js" integrity="sha384-I68UpwZkgCfB4R68KBk7oSjwdRZqI+8zHf73gCvG+J2YFk5fxD3kBQjgt45dGk0Z">
  <script type="module" src="index.js"></script>
</head>
// integrity.js: import map with the SRI hashes of the CrootJS modules. A classic script loaded
// first, because Firefox ignores an import map added after a module or preload started loading.
const map = document.createElement("script");
map.type = "importmap";
map.textContent = JSON.stringify({
    integrity: {
        "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/api.min.js": "sha384-FkrcJYDj82Td9axSh3O+A2TIpwCIg67PsrurLGMr5vk4KnL8c+zONZlBbaMEU0Cy",
        "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/storage.min.js": "sha384-I68UpwZkgCfB4R68KBk7oSjwdRZqI+8zHf73gCvG+J2YFk5fxD3kBQjgt45dGk0Z"
    }
});
document.currentScript.after(map);

Bumping versions with bump-pins.py

The version is written in several places (imports, modulepreload, integrity.js) and the hashes change with every version. Missing one means the same module is downloaded twice, or rejected by the browser. tools/bump-pins.py (just Python 3, no packages) replaces them all in a folder:

curl -fsSLO https://raw.githubusercontent.com/crootjs/lib/main/tools/bump-pins.py
python3 bump-pins.py latest .     # or a specific version: python3 bump-pins.py 0.0.42 .

Every crootjs/lib@x.y.z in .html, .js, .md, .txt, and .json files becomes the new version, and every integrity next to a CrootJS URL gets that version’s hash (from integrity.json, or from the downloaded file for versions before 0.0.42). If one hash can’t be fetched, no file is written. latest reads https://croot.js.org/lib/version.json.

To get a pull request for every new version (like Dependabot), copy this workflow into your repo. In Settings → Actions → General, enable “Allow GitHub Actions to create and approve pull requests”. Pull requests opened with github.token don’t trigger other workflows, so your CI won’t run on them automatically.

# .github/workflows/crootjs.yml
name: crootjs
on:
  schedule:
    - cron: "0 2 * * 1"
  workflow_dispatch:
permissions:
  contents: write
  pull-requests: write
jobs:
  bump:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - env:
          GH_TOKEN: $
        run: |
          VERSION=$(curl -fsS https://croot.js.org/lib/version.json | jq -r .version)
          branch="crootjs-$VERSION"
          if git ls-remote --exit-code origin "refs/heads/$branch" > /dev/null; then exit 0; fi
          curl -fsSL https://raw.githubusercontent.com/crootjs/lib/main/tools/bump-pins.py -o /tmp/bump-pins.py
          python3 /tmp/bump-pins.py "$VERSION" .
          if git diff --quiet; then exit 0; fi
          git config user.name "github-actions[bot]"
          git config user.email "41898341+github-actions[bot]@users.noreply.github.com"
          git switch -c "$branch"
          git commit -am "CrootJS $VERSION"
          git push origin "$branch"
          gh pr create --title "CrootJS $VERSION" --body "https://github.com/crootjs/lib/releases/tag/v$VERSION"

Module Reference

Per-module documentation for crootjs/lib:

See also: lib source code and implementation examples.

Coding Conventions (Mandatory)

All code that uses CrootJS — written by humans or by AI coding agents — must keep HTML, CSS, and JS in separate files, and JS must be loaded as type="module" (except integrity.js for SRI). No inline <style>/<script> and no onclick/style="" attributes in HTML.

Read the full rules & rationale: conventions.md.

Using an AI coding agent? Download CLAUDE.md and put it in your project root — Claude Code follows these rules automatically.

Landing Page

Building an initial landing page at alamat.github.io

Open the prompt

buatkan landing page yang responsif untuk platform digital kampus dengan menggunakan HTML, CSS dan JS ES6+ Module dilengkapi dengan meta tag untuk sosial media (termasuk sharing whatsapp yang tampil gambar, judul dan deskripsinya ketika di share)

Human in the loop:

  1. Make sure the meta tags are present
     <!DOCTYPE html>
     <html lang="en">
     <head>
         <meta charset="UTF-8">
         <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>CrootSS | CSS Mobile Friendly Responsive Component and Template</title>
     <link rel="stylesheet" href="croot.css">
    
         <meta name="description" content="CrootSS: CSS Mobile Friendly Responsive Component and Template." />
         <meta name="keywords" content="CrootSS, CSS, Template, Responsive, Template, Vanilla, html, CSS lib" />
         <meta property="og:image" content="/crootss.png" />
         <!-- Open Graph Meta Tags -->
         <meta property="og:title" content="CrootSS: CSS Mobile Friendly Responsive Component and Template" />
         <meta property="og:description" content="CSS Mobile Friendly Responsive Component and Template" />
         <meta property="og:image" content="https://crootss.if.co.id/crootss.jpeg" />
         <meta property="og:url" content="https://crootss.if.co.id" />
         <meta property="og:type" content="website" />
    
         <!-- Twitter Meta Tags (optional) -->
         <meta name="twitter:card" content="summary_large_image" />
         <meta name="twitter:title" content="CrootSS: CSS Mobile Friendly Responsive Component and Template" />
         <meta name="twitter:description" content="CSS Mobile Friendly Responsive Component and Template" />
         <meta name="twitter:image" content="https://www.do.my.id/crootss.jpeg" />
        
     </head>
     <body>
     </body>
     </html>
    
  2. Make sure there is a robots.txt
    User-agent: *
    Allow: /
    Sitemap: https://alamat.github.io/sitemap.xml
    
  3. Make sure there is a sitemap.xml
    <?xml version="1.0" encoding="UTF-8"?>
     <urlset
         xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
                 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
    
     <url>
     <loc>https://www.bukupedia.co.id/</loc>
     <lastmod>2022-10-18T09:47:19+00:00</lastmod>
     <priority>1.00</priority>
     </url>
     <url>
     <loc>https://katalog.bukupedia.co.id/</loc>
     <lastmod>2022-10-18T09:47:19+00:00</lastmod>
     <priority>0.80</priority>
     </url>
     <url>
     <loc>https://penulis.bukupedia.co.id/</loc>
     <lastmod>2022-10-18T09:47:19+00:00</lastmod>
     <priority>0.80</priority>
     </url>
     <url>
     <loc>https://www.bukupedia.co.id/p/layanan.html</loc>
     <lastmod>2022-10-18T09:47:19+00:00</lastmod>
     <priority>0.80</priority>
     </url>
    
     </urlset>
    
  4. Make sure you have uploaded the favicon.ico file first
  5. Make sure you create a 404.html file

Login Using WhatsAuth

The WhatsAuth API can be used to implement SSO, QR login, and Google Sign-In. Create a new repo containing:

  1. index.html: the main HTML file that loads the QR and GSI JS
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>WhatsAuth | Free WhatsApp API OTP Notif Broadcast Gratis</title>
        <link href="style.css" rel="stylesheet">
    	<script src="main.js" type="module"></script>
    </head>
    <body>
     <div id="hasphonenumber" class="w-full h-screen bg-blue-100 flex items-center justify-center">
         <div class="w-96 bg-white rounded-xl">
             <p class="font-bold text-center mb-4" id="useracclog">Tap/Scan dengan <a href="./camwab.jpg" target="_blank">Camera WA</a></p>
             <div class="flex justify-center mt-2 mb-4" id="whatsauthqr">
                 <img src="loading.svg">
             </div>
             <p class="font-bold text-center mb-4" id="whatsauthcounter">counter</p>
             <p class="font-bold text-center mb-4" id="logs"><a href="https://wa.my.id">WhatsAuth Free WhatsApp Notif, OTP, API Gateway Gratis</a></p>
         </div>
     </div>
    </body>
    </html>   
    
  2. main.js: login setup using crootjs
    import {qrController,deleteCookie,appendGoogleSignin} from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/auth.js";
    import { wauthparam } from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/config.js";
       
    wauthparam.auth_ws="d3NzOi8vYXBpLndhLm15LmlkL3dzL3doYXRzYXV0aC9wdWJsaWM=";
    wauthparam.keyword="aHR0cHM6Ly93YS5tZS82MjgzMTMxODk1MDAwP3RleHQ9d2g0dDVhdXRoMA==";
    wauthparam.tokencookiehourslifetime=18;
    wauthparam.redirect ="/auth"
    deleteCookie(wauthparam.tokencookiename);
    qrController(wauthparam);
       
    const url="https://asia-southeast2-awangga.cloudfunctions.net/bukupedia/auth/users";
    
    const client_id="239713755402-4hr2cva377m43rsqs2dk0c7f7cktfeph.apps.googleusercontent.com";
    
    // Call the function that appends the element
    appendGoogleSignin(client_id,url);
    

    Change the wauthparam.keyword variable to match the number registered with WhatsAuth. Use Base64 decode and encode to update the keyword string above. image

For the additional files:

  1. style.css
  2. loading.svg

Don’t forget to add your domain in the Console under APIs & Services - Client ID for Web application
image

Auth Repo

To authorize between the frontend and the backend, you need one additional repo named auth (set in the qr.js settings as /auth). In the index.html file

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="index.js" type="module"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Selamat Datang di Naskah Bukupedia</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="scene">
        <div class="shadow"></div>
        <div class="jumper">
          <div class="spinner">
            <div class="scaler">
              <div class="loader">
                <div class="cuboid">
                  <div class="cuboid__side"></div>
                  <div class="cuboid__side"></div>
                  <div class="cuboid__side"></div>
                  <div class="cuboid__side"></div>
                  <div class="cuboid__side"></div>
                  <div class="cuboid__side"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      
      </div>
</body>
</html>

In the index.js file

import {getCookie} from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/cookie.js";
import {getJSON} from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/api.js";
import {redirect} from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/url.js";

if (getCookie("login")){
    getJSON("https://asia-southeast2-awangga.cloudfunctions.net/florka/data/user",responseFunction,"login",getCookie("login"));
}else{
    redirect("/login");
}


function responseFunction(result){
    console.log(result);
    if (result.status === 200){
        redirect("/dashboard");
    }else{
        redirect("/daftar");
    }
}

and the style.css file

Integrating WhatsAuth with JSCroot and GOCroot

Tutorial Web

For your own development, see the WebHook Deployment Guide