Eleventy

As soon as I felt like the site was ā€˜doneā€™. I started experimenting with Eleventy (11ty), and I very quickly fell in love with it. Which in short means Iā€™ve rewritten the site from scratch, again.

Whatā€™s wrong with Next?

Nothing in particular. I really like Next, in general itā€™s very well designed and built, itā€™s a joy to use. The balance it strikes between static and dynamic is perfect, and I really appreciate how simple things like API routes are to build out of the box.

But, it just feels like overkill for a site as small as this. The site Iā€™m building is almost entirely static, apart from the listening statistics on the journal pageā€”which are loaded client side. So it makes no sense for my pages to bundling so much JS, it seems like the most basic Next site will include at least 100kB of JS that I do not need. I was particularly frustrated when switching to react-markdown to render content as HTML bumped the bundle size by another 20kB, which isnā€™t ideal considering all the HTML should be pre-rendered.

I could try exporting the site as static HTML, but that would cause more headaches, for example the API routes would stop working properly.

Iā€™m really looking forward to using Next again in future for something a little advanced, but itā€™s time to switch.

Why Eleventy?

Eleventy is a very simple static site generator. Getting started is as simple as:

yarn add @11ty/eleventy
echo '# Hello, World!' > index.md
yarn run eleventy

Thatā€™s all thatā€™s needed to get a workingā€”albeit kinda uselessā€”static site, very simple. I am a big fan of this config-less approach, and super fast startup.

Making the switch

I can still grab all of my content data from Contentful. Like everything else Eleventy makes this easy: add a folder named ā€œ_dataā€, within that folder a JS file that returns an object of data, in my scenario data from Contentful, that data is immediately made available in HTML templates. Again, super simple.

This simplicity has enabled me to progressively enhance as I move forward. For example, I started out by writing all my CSS in a single file (Iā€™m using CUBE CSS this time), once this file started getting longer I installed PostCSS, and the postcss-import plugin meaning I could then use the SCSS-like @import to split up my CSS. While I was at it I also added the css-nano plugin which minifies the CSS for me. This progressive approach means that I can add the tools and features that I need when I need them, which is the opposite of the ā€˜kitchen sinkā€™ approach that some of the React world embraces.

As a result of the switch so far my homepage has gone from around 600kB to around 130kB, which is a massive improvement.

Eleventy does not provide the incredible API routes that Next does, so I have converted most of those routes to Netlify Functions, which was an easy process thanks to Netlifyā€™s excellent design.

For the very small amount of client-side javascript that I do need Iā€™ve switched to Alpineā€”which is worth itā€™s own post. In short I now do not need a JS bundler, and the download size has gone from at least 100kB on every page to around 8kB (gzipped) on the only page that needs it.

Overall I am very happy that I made the switch.

Recent changes
  1. Fix ESLint warnings

See all changes