📎 Webclip
Little helpers: a tweet-sized JavaScript templating engine
The post argues that JavaScript libraries do not need to be large to be useful, especially for single-page apps, short-lived event sites, visualizers, and small helper code. In that context, the author prefers a very simple templating function over searching for existing engines.
Reading notes#
- JavaScript libraries can be useful without being big or clunky.
- For single-page apps, short-lived event sites, and visualizers, small helper code is often faster to write than searching for a prebuilt solution.
- The example is a minimal templating function designed to fit into a tweet.
- The function loops through the data object and replaces each
{key}occurrence in the template string with the corresponding value. - It works for simple messages such as “Hello {who}!” and “Hello {who}! It’s {time} ms since epoch.”
- For larger templates, the author would likely use an engine that stores HTML templates in
<script>tags. - The post adds that
replacecan execute functions automatically, which halves the code size.
