Skip to main content
Backend scripts support import / export syntax to share functions, constants, and objects between pages. Create a “module” page with exported code, then import what you need in any other page’s backend script.

Quick example

Create a page (e.g. slug app) with shared functions:
Import and use them in another page:

Import specifier formats

All of these resolve to the same page slug app:
The resolution rules:
  1. The .js extension is stripped
  2. Leading ./ or ../ prefixes are stripped
  3. The remaining string is used as the page slug to look up
For nested pages, the slug path is preserved:

Named imports

Import specific exports by name:

Default imports

Use export default for a module’s primary export:

Multiple modules

Import from several pages in the same script:

Module pages work on their own

A page with export statements still works when visited directly — the export keywords are silently stripped before execution. This means you can add setVariable calls alongside exports for the module page’s own rendering:
When another page imports getPlans, only the function is used — the setVariable call in the module runs inside the importing page’s context too (both scripts share the same sandbox).

Supported export syntax

Limits

Supported import shapes

Each import line must be either a default import or a named import — not both on the same line:
You can combine classes and functions from the same module with named imports, or import a class from one module and helpers from another. Exported functions may return nested objects, arrays of objects, or build structures from parameters — this is fully supported after inlining:

How imports work

When a backend script contains import statements:
  1. Import statements are parsed and removed from the script
  2. Each module specifier is normalized to a page slug
  3. The module page’s <script scope="backend"> code is fetched
  4. export keywords are stripped from the module code, turning exports into regular declarations
  5. The module code is prepended to the importing script
  6. The combined code runs as a single script in the sandbox
Imported code is merged into your script before it runs — it is not loaded separately at runtime. It shares the same scope as the importing script, with access to the same globals (setVariable, session, request, etc.).