Skip to main content
The ZEN Engine compiles to WebAssembly, allowing you to evaluate decisions entirely in the browser with no backend required.

Installation

Server requirements

WASM requires SharedArrayBuffer support, which needs these HTTP headers:
Example Vite configuration:
vite.config.ts

Basic usage

Loader

The loader pattern enables dynamic decision loading from remote sources. Combined with ZenDecisionContent for pre-compilation, this provides optimal performance for multi-decision applications.

HTTP handler

When decisions make HTTP requests to external APIs, use httpHandler to proxy requests through your backend. This is necessary when the frontend cannot directly access services behind a firewall or private network:
Your backend proxy can forward requests to internal services, add authentication headers, or handle IAM credentials.

Error handling

Using try-catch:
Using safeEvaluate:

Tracing

Enable tracing to inspect decision execution:

Expression utilities

Evaluate ZEN expressions outside of a decision context:
Synchronous versions are also available:

Best practices

Use ZenDecisionContent for caching. Pre-compiling decisions avoids repeated parsing overhead. Cache compiled content in a Map keyed by decision name. Initialize the engine once. Create a single ZenEngine instance at application startup and reuse it for all evaluations. Implement a loader for dynamic decisions. The loader pattern centralizes decision loading logic and enables caching at the source. Call dispose() on cleanup. Release engine resources when the application terminates to prevent memory leaks.