Five simple tips for teachers to get the most out of Firefly

Firefly is a great way to set and organise work remotely but using its full potential requires a little thought.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Why I migrated my website from GatsbyJs to Eleventy

I announced it on twitter last week and here you go with my new blog post about the migration from GatsbyJs to 11ty/Eleventy. In this post, I explain to you why I migrated to Eleventy, what were my challenges and how you can avoid them.

I try to have about 2 hours to one day a week where I try something new for education purposes. So I decided to try out Eleventy. I thought I could use it for my clients who only need a static landing page. I ended up migrating my whole website from GatsbyJs to 11ty.

In this post, I show you why I migrated my website from GatsbyJs to Eleventy, what my challenges were and how you can avoid them. This post tries to outline the main advantages and disadvantages of Eleventy compared to GatsbyJs.

Eleventy is a simple static site generator. That’s it. It uses data and templates to generate HTML files you can upload to your hoster and serve them statically.

That is almost all you need to say about Eleventy. It is fascinatingly simple. Of course, we are going to dive deeper, and there is a lot more to mention, but the paragraph above describes 11ty in its core concept.

index.md

What if you have more complex content that you can not display with Markdown? Eleventy supports multiple template engines you can use.

index.md

Working with data in eleventy is actually very simple. The data is merged from different sources before the engine renders the template. The data-merging is called Data Cascade and is contains the following parts.

You can use Eleventy without any configuration, but if you want to add some additional features or use a plugin you can add it to your .eleventy.js file and expand the functionality.

Gatsby is a static site generator as well. It is React-based and uses GraphQL. It is preconfigured and has used many tools you need to implement usually by yourself like webpack or a service worker. Gatsby uses the pages directory to create each page for your site. It has a huge community and a wide range of plugins with whom you can expand the functionality of your website.

My site was slow even while I used blazing-fast GatsbyJs. Of course, there were many issues which weren’t related to Gatsby, but Gatsby was part of the problem. I spend hours over hours to optimize my site. Even though I know what I am doing, it was quite hard and took much longer than developing my website from scratch.

I wanted to reduce the amount of JavaScript and was quite successful with a plugin called gatsby-plugin-preact preact it replaces React with Preact and cut the bundle files size of my framework-[hash].js from ~40kB to 8.6kB. That was great, but at the same time, it was a bit strange to erase the developing framework React at build time.

Not to mention that I use lazy loading like a freak so additionally, I have 20 requests to JS files that are loaded later between 2kB and 25kb. You could say let’s reduce the JavaScript of our components. I did this for hours. I deleted code, I changed libraries, and I removed functionality.

Here comes Eleventy. At this time now, I migrated all my content to 11ty and implemented all interactions with JavaScript that I need. I now have one main.js of 2.2kB and two bundles that are lazy-loaded with webpack on the pages that need them. One with 941 B and one with 678 B. I didn't remove any functionality.

The following table shows you the size of all MIME Types before and after the migration.

Before

GatsbyJs Bytes

After

So where did I stated? index.js. Nope. As my home page is an overview page I started with my last blog post. I write my blog posts in markdown and use frontmatter in the head of the file for additional information. This blog post you currently reading looks like this:

These files have quite some information in it. In Gatsby, I needed to create NodeFields to query them. So for every entry, I did:

After one hour, I migrated all my posts content without the images. I was convinced and decided to migrate my entire content. That was what I was looking for.

I continued by defining a layout for my base pages and my blog pages to serve different CSS and JS files. I built the main components and Nunjunk partials like the header and the footer, and I created some shortcode components like a button.

Images were my biggest problem. My site contains a lot of header images that I want to render in a picture-tag with correct sizes and formats that the browser can decide which image it should download. Gatsby has a smooth plugin that handles images, and for Eleventy, I chose the plugin eleventy-img and wrote a Nunjunk async shortcode to render the images before the blog content starts.

That worked quite well for all Nunjunk templates, but I could not use them in my blog posts as they are based on Markdown. For all Maordown images below the fold, I implemented a workaround. There might be a better solution, and it still feels a bit dirty, but for now, it works.

Additionally, I wanted to have my image files located where the blog post file is. This makes it easier for me to maintain them and to cross-post them to dev.to, for example.

So my file structure looks like this:

No, not at all. Gatsby was a wrong choice for me, having my requirements and wanting to have a site without much JavaScript, but GatsbyJs provides some great features. If you are struggling with JavaScript, you should consider migrating to Eleventy as well. Eleventy is fast and flexible not only while you are developing but also during runtime.

I migrated my website in one week from Gatsby to Eleventy. So for the moment, I am delighted and satisfied. For sure there are still some open tasks which I will work on the next weeks. If you are thinking about migration, I recommend you to try out Eleventy. It is fun, and you will love it! ♥️

In this post, I tried to show you why I migrated my website from GatsbyJs to Eleventy and why I think this is important for a fast site.

Cheers Marc

Add a comment

Related posts:

Difference Between RAM And ROM in Mobiles.

Mobile memory mein RAM or ROM ak bohat hi impotant part hein. Ye mobile ky sath sath dosri devices yani laptop or computers mein bhi paye jaty hein. Mobile mein in ka bohat hi aham kam hota hai. Ye…

What is the water absorption rate of the nylon series?

As a PA6 Compound Manufacturer, there is some information to share with you. Plastic products or injection molding products are widely used and are high-tech materials for plastics, iron, copper and…

Baking Cakes

I baked the man a cake. Not just any cake. A birthday cake. A lemon one. In a bundt cake pan — which I also had to purchase. Because the man I was seeing back in 2017 said he liked lemon cakes and a…