3 ms·
Lit-html seems like a more fleshed-out version of this: https://github.com/Polymer/lit-html https://github.com/Polymer/lit-html
by numtel 8y ago
Lit-html seems like a more fleshed-out version of this: https://github.com/Polymer/lit-html https://github.com/Polymer/lit-html
- spankalee 8y agoLooking at the code, lit-html should be more efficient at rendering, much more efficient at updating, and safer. Lit-html parses each JS template only once, before interpolation, then caches the resulting HTML template. It clones that template for each new instance, then critically, finds the dynamic parts and directly updates the instance DOM on re-renders. This library looks like even though it uses HTML templates, it creates a new one for each render and update. Not only will that be slower (from parsing, DOM manipulation, layout and paint) because it recreates all the DOM nodes it won't play nice with anything stateful like forms, or many custom elements. It also looks like it might have XSS vulnerabilities from interpolating data before parsing. I'm happy to see more libraries use tagged template literals though. They're purpose-built for embedding DSLs like HTML, their cachability means you can get amazing performance from them, and they're not non-standard syntax extensions like JSX, so don't require a custom compiler.