Eleventy, understanding yet another static site generator

Eleventy, understanding yet another static site generator

Eleventy is a static site generator that is feature rich and yet focuses on simplicity and rapid builds. Compared to Astro, Gatsby, Jekyll etc. Eleventy can build pages a maginitude faster making it an ideal chose for websites that want to host large number of statically generated pages.

Table of content

  1. Eleventy is real fast

  2. Getting started with Eleventy

    1. Creating templates
    2. Run development server
  3. Eleventy vs Jekyll

  4. Gatsby vs Eleventy

  5. NextJS and Eleventy

  6. Criticism of Eleventy

  7. Conclusion

Eleventy is real fast

Mozilla moved from Jakyll to Eleventy long time ago and wrote a blog post. This was a classic real world scenario where even Mozilla did not know how much performance gain to expect. Yet, when they ran it they found that while Jekyll took 10+ minutes to build, Eleventy did it in 3 seconds. Yes. That fast.

What was immediately apparent was how fast Eleventy is. The entire site was built in under 3 seconds. That is not a typo; it is 3 seconds not minutes.

source

Eleventy is fast and lightweight. It is a replacement of Jekyll which means it plays really well with Jekyll sites with minimal changes. Also unlike Gatsby, Eleventy is extremely simple. You basically give it a directory full of templates and data and its does the rest. It can work with any templates including liquid, mustache, Nunchuks and what not. It can integrate seemlessly into you Nextjs or Vue app as well.

Getting started with Eleventy

The steps to get started are extremely simple. All you need is nodejs installed on your machine.


mkdir eleventy-sample
cd eleventy-sample
npm init -y
npm install @11ty/eleventy --save-dev

# Run eleventy
npx @11ty/eleventy

Creating templates

You can create HTML templates or mardkdown files as templates.


echo '<!doctype html><title>Page title</title><p>Hi</p>' > index.html
echo '# Page header' > README.md

npx @11ty/eleventy

This comment will generate the templates.


[11ty] Writing _site/README/index.html from ./README.md (liquid)
[11ty] Writing _site/index.html from ./index.html (liquid)
[11ty] Wrote 2 files in 0.04 seconds (v2.0.1)

Run development server


npx @11ty/eleventy --serve

[11ty] Writing _site/index.html from ./index.html (liquid)
[11ty] Writing _site/README/index.html from ./README.md (liquid)
[11ty] Wrote 2 files in 0.04 seconds (v2.0.0)
[11ty] Watching…
[11ty] Server at http://localhost:8080/

Eleventy vs Jekyll

Eleventy and Jekyll are pretty much alike, except that Eleventy is lot more faster. Jekyll however is lot more popular and is around for a much longer time. If you have a site that is lot larger and you are currenly using Jekyll please consider moving to Eleventy.

Gatsby vs Eleventy

Gatsby is more flexible react based static site generator. It is primarily designed to fetchdata from API and then generate files based on that though it can also work on markdown and other templates. However Gatsby is extremely slow and can not scale beyond few thousand pages in reasonable build time.

NextJS and Eleventy

Nextjs is a full fledged framework to build applications. It does support static site generation. However, Nextjs and Eleventy aren't meant to replace each other. NextJS is suited for building large scale apps and not just static sites but Eleventy is purely for static sites.

Criticism of Eleventy

Criticism of Eleventy would be same as criticism of many static site generators. Static site generators generate ton of repitative HTML and pages which are easier to serve but are static and hence can have limited features. In many cases a simpler, server side rendering might be simply better.

If you are considering Eleventy, chances are you are looking at generating sites that have thousands of pages. Nothing wrong with that but a question you might ask is why not have a PHP or NextJS based static site generator for the same ? The cost difference is not going to be very much if you ask me.

Conclusion

Eleventy is yet another static site generator but indeed is better than many existing choices and most certainly worth using for its high performance compared to Jekyll.