- ClayJS
- Reference
- Setup
- The script tag
The script tag
The script tag, versioned URLs, and loading plugins through the query string.
Every clayjs URL carries a version, because a saved document hardcodes its script tag and there is no way to reach it afterwards to change it.
Loading#
<script src="https://clayjs.com/v1/clay.js"></script>
The default build includes the save lifecycle and rich text (editable). Plugins load conditionally through the URL, in the browser only.
Versioned URLs#
Two forms:
| URL | What it serves |
|---|---|
/v1/clay.js | The newest 1.x release. Rolls forward with fixes and features, never across a major version. |
/1.0.0/clay.js | That exact release, forever. Cached for a year as immutable. |
/v1/clay.standalone.js | The whole library in one file, for a page that must load with no network. Same query params. Details on Offline. |
Use /v1/ unless you have a reason not to. Both forms exist for every satellite, so /v1/clay-ui.js and /1.0.0/sap.js work the same way. Published versions are listed at versions.json. There is no unversioned URL: clayjs.com/clay.js was retired at 1.0 and returns 404.
Plugins#
| Param | Meaning | Example |
|---|---|---|
plugins | Comma-separated plugins to load | clay.js?plugins=sync,undo |
exclude | Remove a plugin from the plan: a default-on one, one another plugin brings with it (plugins=page&exclude=upload), or one added on its own, such as derive or upgrade. One exclude= takes a comma list (?exclude=source,richclay); a second exclude= parameter is ignored. | clay.js?exclude=richclay |
Loadable plugins: richclay (default on), source (default on), page (brings live, sync and upload in edit mode), ai-edit (brings wire), cms (brings quickcrop and upload), indicator, menu, sync, live, sortable, undo, unsent, bind-text, quickcrop, upload, people, message, like, wire, demo, visitor-drafts, upgrade, derive. The default-on plugins load in edit mode only. Eight have a checkbox in the configurator; ask for the rest by name. The configurator composes this URL for you.
visitor-drafts turns the page into a free document: a visitor who is not the owner gets the editing UI and their work is kept in their own browser, never on the host (Free documents for visitors). It needs a visitor-drafts="<slot>" attribute on <html> and an api rules tag carrying data-rules-version="1" JSON that parses, and it is inert without them. A viewonly document or a stale token is not draft mode, so ?editmode=true there behaves as it did before draft mode existed. See Free documents for visitors.
derive (the sapjs core) loads by itself, in view mode too, on any page with a [sap] root at boot, and stays idle when full sap.js is on the page; exclude=derive opts out.
Everything else is a separate library (“satellite”) with its own script tag: clay-ui, clay-events, clay-options, clay-dom, clay-router, all.js, clay-utils, clay-internals, clay-data, sap.js. To call a satellite from an inline script right after its tag, wait for it: await clay.loaded.ui (or .dom, .all, .utils, .events, .options, .data, .sap, .internals, .router). See Advanced and Plugins.
npm builds for bundlers live at @panphora/clayjs.
Offline#
For a page with no network at all, the standalone build is every module in one downloadable file. https://clayjs.com/v1/clay.standalone.js is the whole library in one readable file (core, every plugin, every satellite), built from the same source. Download it, keep it beside the HTML file, and load it with the same query params:
<script src="clay.standalone.js?plugins=sync"></script>
plugins= then decides what runs, not what downloads, and every clay.loaded.* promise exists without a satellite tag. Delete any satellite tags the page had: the file carries them all, and a second sap.js mounts a second runtime. clay.Sap and clay.extractData, which a tag defines synchronously, arrive one microtask later here; await clay.loaded.sap (or .data) covers both. /1.1.0/clay.standalone.js is that exact release, pinned, and every later release has the same form; the npm tarball carries it at dist/clay.standalone.js; the file’s first line names its version.
Two things still reach the network, both opt-in: the CMS sidebar’s font comes from jsDelivr and falls back to the system monospace, and autosave debugging (localStorage key clay:debug:autosave) imports its diff library from esm.sh. Saving still needs a host that writes the file; HTML Clay does that on the machine itself, with no network.
The one-paragraph integration#
To make a static HTML file malleable: add <script src="https://clayjs.com/v1/clay.js?plugins=sync,undo,indicator,menu&exclude=richclay"></script> as the last element inside <body>. Add an autosave attribute to the <html> element. Add editmode:contenteditable inert-contenteditable="plaintext-only" to each element a person should edit as plain text (headings, labels, list items). Enter adds a line break to plain text, so make Enter blur any element that must stay on one line. For formatted text, drop &exclude=richclay from the script and add an editable attribute to those elements instead (headings, paragraphs, note containers). Add a persist attribute to any form control whose value should survive saving. Mark editing controls with show-when:editmode="true" and load clay-options.js, so viewers never see them. Put UI that a script builds or changes at runtime inside clay="editor-ui". The menu plugin in that script gives a person who can edit an Edit switch, because the document opens in view mode, even for its owner. Add opens-in="edit" to <html> on a page that should open ready to edit. Do not write any save logic or add a save button: clayjs saves the whole document automatically, and the host writes it to disk.