Get the latest tech news

Templating in JavaScript, from Zero Dependencies on Up (2021)


Writing about the big beautiful mess that is making things for the world wide web.

But that’s kind of the point: you trade that sugar for zero dependencies, leveraging vanilla JavaScript with template literals and functions returning strings. You could have a render() function which wipes the innerHTML of a section of the document with fresh data each time you need to re-render it—a plausible scenario for many small projects or pages which are progressively enhanced. Since it’s merely functions returning strings, it also allows me to easily render others things— like XML for a feed —and it let’s me skip the quirks of any particular templating framework, like having to write the attribute className instead of the HTML-compliant class.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of javascript

javascript

Photo of Dependencies

Dependencies

Related news:

News photo

QuickJS, the Next Generation: a mighty JavaScript engine

News photo

Show HN: Simulating 20M Particles in JavaScript

News photo

Show HN: Execute JavaScript in a WebAssembly QuickJS sandbox