Dev mode vs production mode
| Behaviour | Dev mode (default) | Production mode |
|---|---|---|
| Source file mtime check | On every render() call | Never |
| Automatic recompilation | Yes — when source changes | No |
LexDebugger active | Yes | No |
__lex_debug__ payload injected | Yes | No |
| Precompiled index used | No | Yes |
| Source I/O per request | Yes | Zero |
Dev mode
In dev mode, everyrender() call checks whether the source .lex file’s filemtime has changed since it was last compiled. If it has, the template is recompiled automatically. LexDebugger is active and injects a __lex_debug__ JSON payload into the rendered HTML, which powers the Chrome DevTools extension.
Dev mode is the default — you do not need to configure anything to use it.
Production mode
In production mode, all source-file I/O is skipped. The engine looks up each template in a precompiled index (.lexer/compiled/index.php) and serves the compiled PHP file directly — no mtime checks, no recompilation, no disk reads beyond the compiled file itself. LexDebugger is disabled automatically; no debug data is ever injected into responses.
Enabling production mode
- lex.config.json
- Fluent API
Set
"production": true in your config file:Lexer::fromConfig() reads this value on startup and enables production mode automatically.Deployment workflow
Compile all templates
Before deploying, run the Lex CLI compile command. It walks every template in your configured view paths, runs the full compilation pipeline for each one, and writes the compiled PHP files to This also builds the precompiled index at
.lexer/compiled/..lexer/compiled/index.php.Deploy compiled output
Include the
.lexer/ directory in your deployment. The engine reads index.php from it at startup in production mode — without it, templates cannot be served.If you normally exclude
.lexer/ from version control (recommended for dev), make sure your CI/CD pipeline runs lex compile after checkout and before packaging the deployment artifact.Enable production mode
Set
"production": true in lex.config.json or call ->setProduction() in your application bootstrap. The engine will use the precompiled index from step 1.The precompiled index
The index file lives at.lexer/compiled/index.php and is a plain PHP file that returns an associative array mapping absolute template paths to their corresponding compiled file paths:
FileCache::indexLookup() performs a single array key lookup per render call. If the compiled file exists on disk, it is served immediately — there are no further filesystem reads before execution.
Do not edit
index.php by hand. It is written atomically by FileCache during compilation and will be overwritten the next time you run lex compile.LexDebugger
LexDebugger is the layer that wraps render() in dev mode. It collects component tree data, section contents, cache hit/miss events, and render timing, then serialises them as a __lex_debug__ JSON payload appended to the HTML response.
In production mode setProduction() sets an internal flag that causes render() to call ViewEngine::render() directly, bypassing LexDebugger entirely — there is no conditional check at render time, and no debug data is ever allocated or serialised.