micro-template.js

A minimal, blazing fast JavaScript template engine for hackers.

npm version GitHub stars MIT License

Features

Getting Started

In HTML

<script type="application/x-template" id="tmpl1">
  <div><%= message %></div>
</script>
<script type="module">
  import { extended as template } from 'https://cdn.jsdelivr.net/npm/micro-template@2.1.2/lib/micro-template.js';
  const html = template('tmpl1', { message: 'Hello, world!' });
  document.body.innerHTML += html;
</script>

In Node.js

npm install micro-template
import fs from 'node:fs';
import { template } from 'micro-template';

template.get = id => fs.readFileSync('tmpl/' + id + '.tmpl', 'utf-8');

const result = template('tmpl1', { message: 'Hello, Node!' });
console.log(result);

Benchmark

benchmark (vs ejs, 10x+ faster) on perf.link