DEV Community

I built a JS template engine 3x faster than EJS

Ben Gubler on April 11, 2020

After hundreds of hours of development, I finally released my open-source project last week. Eta is a pluggable, lightweight, and super-fast JavaSc...
Collapse
 
helvecioguimaraes profile image
Helvecio

Hey, Ben, congrats on building Eta, sounds like it is bound for great success. I started learning web development (I'm a chemical engineer working with investment brokerage) a few weeks ago through Udemy. I came across EJS and found it rather interesting. However, it looks really odd to me to have all that Javascript within the HTML code. I therefore wonder if EJS is really widely used or is just a niche framework, for very specific purposes. Thanks.

Collapse
 
nebrelbug profile image
Ben Gubler

Thanks (and sorry for the late reply)!

EJS and lodash.template (a similar alternative library) each have about 6 million downloads per week. I think many JavaScript developers choose to use them because -- even if JavaScript inside HTML is a little bit strange-looking -- they know it'll be readable to other JavaScript developers, rather than making them learn some new template syntax.

A great example of a project that uses Eta currently is Docusaurus, which uses Eta (ex. in github.com/facebook/docusaurus/blo...) to generate server-side builds.

Collapse
 
damiantoczek profile image
Damian

I must truly say that Eta is amazing. Everything that annoyed me in EJS is now no more.
I just changed the tags to {{ }} because i know that I won't ever use it and it's faster to type. Even tho I haven't used handlebars.
Keep it up, I just hope this project will keep going, it has such a huge potential! For me it's already huge.

Collapse
 
vandisefano profile image
vandisefano

Cool, I was wondering if it was possible to generate static files with Eta (pre-build).

I have a project where users can create posts with a wysiwyg editor.
What I want to achieve is try to take that post, inject it into a predefined Eta template and export a static (HTML) page from it (with header, footer, sidebar...). Then I would host that page on a CDN for quick access.

Since the content will never change there is no need to compile the HTML at runtime.
I was wondering if something like that would be possible with Eta?

User creates post -> server compiles it to a static HTML file from pre-define Eta templates -> server uploads to CDN -> user can access page from CDN

Would this be suited for my needs? Thanks!

Collapse
 
nebrelbug profile image
Ben Gubler

It sure would! One of the best use cases for Eta is generating static content. Right now, for example, Docusaurus uses Eta to generate static HTML for SSR builds.

Collapse
 
daviddalbusco profile image
David Dal Busco

It looks like a loooooot of work! Congratulations for the launch, it looks slick 👍

Collapse
 
nebrelbug profile image
Ben Gubler

Thank you!

Collapse
 
machineno15 profile image
Tanvir Shaikh

can it re-renders template on state/object change ?

Collapse
 
nebrelbug profile image
Ben Gubler

If you manually re-render it or implement a state listener (like React). That kind of functionality is more common in Virtual-DOM engines.

Collapse
 
abdullaharik profile image
Abdullah Arık

Hi Ben, sounds good. I want to use it in 11ty, what do you offer?

Collapse
 
nebrelbug profile image
Ben Gubler

Thank you!

Right now, Eleventy doesn't support Eta. However, you can upvote the enhancement request here (github.com/11ty/eleventy/issues/1416) or submit a PR to add support!

Collapse
 
cyrusel profile image
cyrusel • Edited

Great job Ben. I tested it, it's fantastic!
Why don't you create an Eta runtime version (like squirrelly) for complied templates? :)

Collapse
 
nebrelbug profile image
Ben Gubler

Thank you!
I thought about creating a runtime version, but ended up deciding against it because even the full version of Eta is quite lightweight.
It would be quite easy to create a separate runtime version though... if you're interested in creating one I'll link to it!

Collapse
 
ajaypatel profile image
FoodBite

Very nice

Collapse
 
nebrelbug profile image
Ben Gubler

Thanks!