26 points · by tosh · 2y ago · 27 comments
Years back I dove completely in on Svelte and even wrote my own SSG that helped kick off the Islands/partial hydration crazy... Elder.js. It was fun, but burnt me out of open source.
Today, I only pull for a template language and deal with SSR/Hydration for pages that really need it.
I want JS projects that don't break 6 months after the last build. The way you get that is by not adding more dependencies and not chasing the latest craze.
I was somewhat recently trying to get a 3 year old JS project working. I felt like I was alone in an Egyptian pyramid wondering if I had missed the funeral.
I've settled on ``document.createElement()``: it's a bit rough visually, but that's pretty much the only downside (I've found the time gained with templates to be negligible in front of the overall development time).
A big bonus of dealing with genuine objects is that there's room to extend them to e.g. store additional state/data/handlers/etc., which might otherwise be cumbersome to be set via attributes & cie.
Also Honojs (hono.dev) has a built in HTML function which is quite good and I've used extensively.
I noticed the article doesn't mention escaping HTML, which you probably should do if you're expecting user input. Fortunately, such a utility is included in Deno's standard library: https://jsr.io/@std/html/doc/~/escape
Similarly, for XSS, the `xss` package on npm works great for Deno.
For example, a plain string template will not help with selective DOM updates; that’s why we end with a tree DSL like JSX.
For many different reasons, you’ll like to have lazy component rendering. That’s why using `Component(props)` is not the same as `factory(Component, props)`.
I’m not saying that the author is wrong or right. If you only want a server-side template or one-off template for a simple page, then using JS/TS string templates is better than relying on a DSL like Handlebars or Pug. The client-side story is a bit different, and that’s why there are so many frameworks for it.