Compiler
To provide these abstractions without sacrifising performance, Mapl uses a compiler to optimize the fetch handler before request time.
JIT compilation
Mapl exposes jitc()
to compile an instance to a fetch handler with new Function()
:
AOT compilation
You can precompile the fetch handler content with aotfn()
:
Then load with necessary dependencies to create a fetch function:
This approach often results in 5x faster startup time than JIT compilation.
Since AOT compilation does not use new Function()
, this unblocks Mapl on edge runtimes where eval()
and new Function()
are not allowed (Cloudflare Workers, Vercel Edge, …).
Compiler options
You can pass an option object to aotfn
and jitc
.
exposeStatic
If set to true, prebuilt routes will be exposed as the static
property in the final compilation result instead of registered to the router.
Example usage with Bun: