Constants
Define compile-time constants with type checking. Use them throughout your configuration for centralized management.
#const API_TIMEOUT INTEGER = 5000
#const ORIGIN STRING = "api.example.com"
For Loops
Generate repetitive code blocks dynamically. Iterate over ranges or lists to create backends, directors, or ACL entries.
#for region in ["us", "eu", "asia"]
backend origin_{{region}} {
.host = "{{region}}.example.com";
}
#endfor
Conditionals
Conditional compilation based on constants and compile-time expressions. Different code for dev vs production.
#if PRODUCTION
set req.http.X-Debug = "false";
#else
set req.http.X-Debug = "true";
#endif
Functions
Define reusable functions with parameters and return values. Compiles to VCL subroutines with automatic header-based parameter passing.
#def normalize(url STRING) -> STRING
return std.tolower(url);
#enddef
set req.url = normalize(req.url);
Inline Macros
Zero-overhead text substitution for simple expressions. Expands inline without function call overhead.
#inline is_mobile(ua)
regsuball(ua, "(?i)mobile|android", "")
#endinline
Includes
Modular code organization with include-once semantics and circular dependency detection.
#include "backends.xvcl"
#include "functions.xvcl"
#include "security.xvcl"
Template Expressions
Evaluate Python expressions at compile time. Use constants and loop variables for dynamic code generation.
#for i in range(10)
if (req.http.X-Port == "{{8000 + i}}") {
set req.backend = app{{i}};
}
#endfor
Variables
Declare and initialize local variables in a single step with #let, reducing VCL boilerplate.
#let timestamp STRING = strftime({"%Y-%m-%dT%H:%M:%SZ"}, now);
#let cache_key STRING = req.url + req.http.Host;
Source Maps
Debug generated VCL with comments marking included regions and generated function definitions.
xvcl main.xvcl -o main.vcl --source-maps
Structured Diagnostics
Errors include rule IDs, source provenance across includes, actionable help text, and suggestions. Machine-parseable JSON output for CI and editor integration.
error[const-redefined]: Constant 'PORT' is already defined
--> config.xvcl:5
| included from main.xvcl:2
= help: Remove duplicate or rename