JavaScript rules and upload validation¶
A template may ship JavaScript — script.js at the ZIP root, inline <script> blocks in
index.html, and further files under assets/ referenced with <script src>. It runs
after the template's HTML and CSS have loaded, inside the sign player's page, so it has to
play by the player's rules. This page lists them and the upload messages that enforce them;
how to structure the code so it survives template switches is on
Template JavaScript best practices.
What JavaScript is for¶
Manipulating the DOM and CSS classes that already exist in your template:
// Toggle classes for animations
document.querySelector(".banner").classList.add("fade-in");
// Change text the player does not bind
document.getElementById("footer").textContent = "Doors open 08:30";
// Timed behavior, cleaned up automatically when the template switches out
window.preseriaTemplateInit = (ctx) => {
ctx.setInterval(() => document.body.classList.toggle("pulse"), 5000);
};
Use plain JavaScript as browsers run it (no TypeScript, JSX or build step), keep it short,
and avoid redefining globals or functions the player owns. Anything that creates timers,
listeners or fetches belongs inside preseriaTemplateInit(ctx) using the ctx.* helpers.
What is rejected at upload¶
The upload scans every script — script.js, inline blocks, and files under assets/ — and
refuses the template when it finds:
| Pattern | Why | Message |
|---|---|---|
A string that names a bundled asset: 'assets/…', './assets/…', '../assets/…' |
Asset paths are rewritten by the server when the template is published; a path written in JavaScript breaks | Illegal local runtime loading pattern(s) found in … |
fetch('local/path') — anything but an absolute http(s)://, protocol-relative // or data: URL |
The template's own files cannot be fetched at runtime; the sign already has the data it needs | Illegal local runtime loading pattern(s)… |
import x from './…', import './…', import('./…'), new URL('./…', import.meta.url), new Worker('./…'), importScripts('./…') |
Modules and workers cannot be loaded from the ZIP | Illegal local runtime loading pattern(s)… |
<script src> pointing at digital-sign.js, digital-sign-event.js, their preview variants or luxon.min.js |
The server injects the player scripts itself | Template must not include backend-injected scripts |
<script src="data:…"> or javascript: URIs |
They bypass the scan | Inline scripts via data: or javascript: URIs are forbidden |
A local <script src> whose file is not .js, .mjs, .cjs or .ts |
Every local script must be scannable | Local script references must point to a scannable JavaScript file |
| A single script file over 5 MB | Scan limit per file | Template script '…' exceeds maximum allowed size for scanning (5 MB) |
| Scripts totaling more than 20 MB | Scan limit for the whole template | Template scripts combined size … exceeds maximum allowed |
The two scan limits are fixed in the validator; they apply even when the ZIP is well inside the installation's archive limits on the Template library page, which an administrator can configure.
A rejection names the file and the offending line, for example:
Illegal local runtime loading pattern(s) found in script.js:
• fetch('./assets/data/schedule.json')
Do not load local assets or modules directly from JavaScript. All assets must be referenced via index.html or styles.css.
These checks cannot be forced past; fix the script and upload again. Reference every image,
font and video from index.html or styles.css instead — JavaScript may then toggle the
classes that apply them:
.hero { background-image: url("assets/images/hero.jpg"); }
.hero.alt { background-image: url("assets/images/hero-alt.jpg"); }
External scripts (<script src="https://cdn…">) are not rejected by the scan but should
not be used: signs may be offline, and only bundled files are cached. Download the library
and bundle it under assets/ instead; it loads in authored order and is awaited before
preseriaTemplateInit runs.
Static analysis¶
After these rules, the upload runs a static analysis of the HTML, CSS and JavaScript. Its findings are graded; Error findings stop the upload and can be overridden with Force Upload Anyway, warnings and notes are informational. The checks are listed on What the static analysis checks; the findings are shown on the template's analysis page — see Template Editor and analysis and Template library.
Related¶
- Template JavaScript best practices — lifecycle hooks, timers, re-application
- Getting started with templates — where files may live
- Template library