r/javascript • • 1d ago

Template engine EJS vs Eta for a new Node.js project with SSR(don't want to use NextJS), which to choose?

https://npm-compare.com/ejs,eta/#timeRange=ALL

Hi,
I am about to start a new project with SSR (Node.js); previously, I have used ejs/handlebars. Currently, I am not very familiar much eta.

eta claims to be faster than ejs, anyone worked with both?

Highly appreciate your suggestions/comments.

ejs: https://www.npmjs.com/package/ejs
eta: https://www.npmjs.com/package/eta

Thanks

4 Upvotes

7 comments sorted by

•

u/lanerdofchristian 18h ago

Is it specifically NextJS you're avoiding, or full-stack frameworks in general including SvelteKit, Nuxt, and Astro?

•

u/wasitshafi 16h ago

u/lanerdofchristian, actually, I am trying to look first for pure Node.js server-rendering options available. Mostly because of SEO, previously I have used React & Angular; they didn't perform well when it comes to SEO.

•

u/lanerdofchristian 12h ago

Astro (supports a myriad of component languages) ships zero JS to the browser by default. SvelteKit and SolidStart both have modes for minimal client-side JS with hydration by default (the initial HTML alone is a complete document, JS comes along after to make it fancy) and full prerendered options. All of them have modern dev servers with hot reloading so you don't have to constantly restart your server every time you make a non-template change (e.g. changing a database call).

You don't have to retreat to the days of manually stitching together HTML fragments to avoid an SEO-unfriendly SPA.


To be reductionist, "pure Node.js" contains all of these options, and the "most pure" is literally adding plain JS strings together.

3

u/kevinkace 1d ago

I used ejs on many projects and then used Eta on a new one, tbh I can't recall what led to my decision, but I also can't recall having any regrets and was happy with the decision.

•

u/Ronin-s_Spirit 15h ago

You could always write your own, it can be very easy depending on what you wanna do.

•

u/-jeasx- 9h ago

Have a look the Jeasx:

https://www.jeasx.dev

Server rendered JSX on top of Fastify. The expo shows what can be done with Jeasx:

https://expo.jeasx.dev/

If you want to roll your own solution with SSR and JSX, you can also use the underlying library on its own:

https://www.npmjs.com/package/jsx-async-runtime

•

u/Evgenii_Korolev 1h ago

speed won't really be the deciding factor, both compile templates and can cache them, and on a real SSR page your db calls will take way longer than the render. i'd pick eta for a new project mainly because it has layouts built in, with ejs you end up stitching header/footer includes into every page or pulling in express-ejs-layouts. it's also written in TS so the types are decent. two things that trip people up coming from ejs: data lives on it, and unescaped output is <%~ not <%-.

<% layout('./base') %>
<h1><%= it.title %></h1>

and in base.eta you print the page with <%~ it.body %>.