A page record carries a top-level style object — a sibling of data, not a key inside it — holding the assets written into the document when the page renders: stylesheets ahead of the page, scripts after its content.
Video tutorials for this topic
| Slot | Injected as |
|---|---|
style.javascript | An inline <script>, after the page's content |
style.css | An inline <style> |
style.scriptLinks | <script src> elements |
style.styleLinks | <link rel="stylesheet"> elements |
This is where page behaviour belongs.
req("POST", f"/repository/update-partial/page/{sk}", {
"sk": sk,
"version": rec["version"],
"style": {"javascript": js, "css": css},
}, token=t){"style": {}} clears the slots.
data.style is read by nothing. A payload written there is stored, returns 201, and never executes — no error, no warning. Confirm placement by reading the record back:
print("style" in rec) # True — correct
print("style" in rec.get("data", {})) # False — the wrong placeThere is no practical size limit. A production product customizer runs on 113,115 characters in this slot.
What executes, and what does not
| Where | Executes on a full page load |
|---|---|
style.javascript | Yes |
style.scriptLinks | Yes |
<script> with a body, in the body of data.html | Yes, in place — but not on a page with a data-react placeholder |
<script> in the page's <head> | Yes, but before the body markup exists |
data.style.javascript | No — nothing reads it |
onclick, onload and other handler attributes | Yes — attributes survive intact |
The body of data.html is normally written straight into the server-rendered document, so the browser runs its scripts like a static file's. A data-react placeholder switches the body to the virtual-DOM path instead, which leaves every <script> out of the page. See Pages and rendering.
data-react presets render nothing. The React preset library has been removed, so a data-react placeholder draws nothing — and costs the page its body scripts. Use plain HTML with runtime attributes and custom elements.
No page script runs — style.javascript included — when the visitor arrives by client-side navigation: a link rendered by the host itself, such as the cart drawer or the built-in store and content listings, swaps the page in without loading a new document. Plain <a href> links in your HTML load a full page.
It runs before the runtime exists
style.javascript is written out after the page's content, so your own markup is there when it runs. window.appmint is not — it is still not mounted at DOMContentLoaded — and neither is anything the runtime renders, such as data-source rows.
Gate on what you need:
(function boot() {
if (!document.getElementById('app-root') || !(window.appmint && window.appmint.cart)) {
return void setTimeout(boot, 30);
}
// …
})();Check a real element from your own markup and the specific namespace you use — namespaces mount progressively, so window.appmint alone is not a sufficient test.
Do not substitute DOMContentLoaded. It fires before window.appmint is mounted, so a listener that calls the runtime fails.
Constraints on code in this slot
Globals are not shared with attribute handlers. A function assigned to window from style.javascript is not reliably visible to an inline onclick on a hydrating page. Bind with addEventListener instead of defining globals for markup to call.
Bindings cannot call JS globals. data-bind expressions have Number, Math, parseInt and toLocaleString shadowed to undefined, and the binding renders blank rather than erroring. Use data-format, or compute in code and bind the result.
Make it idempotent. A page can render more than once. Mark what you bind to:
var root = document.getElementById('app-root');
if (root.dataset.bound) return;
root.dataset.bound = '1';Use textContent for record values. Anything a person typed or a record supplied is untrusted; interpolating it into innerHTML is an injection site.
Debugging
Put a flag above the gate while developing:
window.__APP_LOADED = true;
(function boot() { /* … */ })();Then, on the rendered page:
| Reading | Means |
|---|---|
__APP_LOADED undefined | The slot is wrong or empty — the code was never delivered |
__APP_LOADED true, nothing happens | Delivered; your gate never opened |
| Elements found but no behaviour | Bound to nodes that were later replaced by a redraw |
That first distinction — not delivered versus delivered and waiting — separates two completely different problems, and guessing between them is where the time goes.
The Scripts library
When the same code belongs on several pages, keep it in DAM › Scripts (admins only) rather than pasting it into each page's style.javascript.
A script has a name (lowercase letters, numbers, hyphens and underscores, fixed after the first save), a description and a status — Draft, Active or Disabled. Write the code in the editor or upload a .js file. Scripts are plain JavaScript on the window.appmint API, and the editor has a reference panel beside the code: click a method to insert it at the cursor, or look up the declarative HTML attributes that need no JavaScript at all.
Saving hosts the code as a file in your organization's storage — <org>/client-apps/<name>/<name>.js — and records its URL as the script's entry point; Open entry point in the list opens it. To load a script on a page, add that URL to the page's style.scriptLinks. It is written out after the page's content like the inline slot, and loads async, so it needs the same readiness gate.
Related
- Where your code goes — the same ground, with the application patterns
- Pages and rendering — the storage shapes and the parser
- Runtime attributes — the declarative alternative
- Actions reference — what
window.appmintexposes
