Why I moved to Astro from Gatsby
Tags: webdev, astro, javascript, svelte
Published: 2022-03-22 10:33:00

---
title: "Why I moved to Astro from Gatsby"
published: "true"
description: "Why I moved to Astro: a quick look at why I am using Astro JS over Gatsby JS for new static sites and what's good about building with Astro."
tags: "webdev, astro, javascript, svelte"
canonical_url: "https://rodneylab.com/why-i-moved-to-astro/"
cover_image: "https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ru4ra3orsduaniylvh5v.png"
---

## 😢 What's Wrong with Gatsby?

In this post on why I moved to Astro, we take a look at the Rodney Lab Astro site. Before we get into that it is worth taking a quick look at what made me want to switch. As well as that, we look at why Astro was a good fit. I should mention the old site was running Gatsby&nbsp;3. Some of the issues might have been addressed in subsequent releases. The main reason for upgrading was that builds had become slower and increasingly unreliable.  This happened as the number of posts on the site increased. The screenshot shows the deploys screen from the site host over January.

![Why I move to Astro: Screenshot of build console shows repeated failed builds, with build time exceeding maximum allocation.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7og6zm82jlils1a99n91.png)

The builds were taking so long that they exceeded the maximum allowed running time.  If you are having issues with a Markdown site, <a aria-label="Open post on fixing Gatsby slow build times" href="https://paulie.dev/posts/2021/07/gatsby-slow-local-build-times/">Paul Scanlon</a> has written a post on improving things.  I could have applied some of these optimisations or upgraded to the latest Gatsby version.  Instead I preferred to take the opportunity to try out one of the newer build tools.  Incidentally the new Astro site consistently builds in just under ten minutes.

## 🚀 What I like about Astro

Astro uses Vite tooling, like Vue and SvelteKit so it runs at lightning speed, creating a fantastic developer experience.  On top it offers an &lsquo;<a aria-label="Open post on getting started with Astro" href="https://rodneylab.com/getting-started-astro">islands architecture</a>&rsquo; which lets you only add JavaScript to components that need it.  As an example, most of this post is plain HTML with no JavaScript needed. The images lazy load and the Poll has some interactivity so JavaScript is needed there.  I can build the page so the JavaScript for those components only loads once they are visible.  There will be other code, like analytics, which isn&rsquo;t needed immediately. You can tell Astro only to load that once the main thread becomes idle, so you limit the impact on user experience.

### Why I moved to Astro: other Astro Pros

The other main features I like about Astro are that:
- you can write you pages in Svelte &mdash; it supports React and Vue too, and you can pick and mix. The main advantage there is you can try out another framework in an existing app starting with a single component,
- like SvelteKit, it is easy to add routes which output something other than HTML. For  example, you can set up a route to serve a JSON file generated at build time,
- Astro is quick.  The generated page is fast and with Vite under the hood, build times are speedy too.  Anecdotally I am seeing faster build times, than even SvelteKit, though I haven&rsquo;t run scientific tests.

### Lighthouse

You can see the pickup in Lighthouse scores I got switching to Astro from Gatsby:

![Why I move to Astro: Image shows Lighthouse scores for new Astro site. Overall performance score is 100, first contentful paint is 0.3 s, Time to Interactive is 0.3 s, Speed Index is 0.6 s, Total Blocking Time is 0 ms, Largest Contentful Paint is 0.3 s and Cumulative layout shift is 0.001](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/enij1jz8yki9kiiqgxgs.png)

![Why I move to Astro: Image shows Lighthouse scores for old Gatsby site. Overall performance score is 92, first contentful paint is 0.5 s, Time to Interactive is 0.7 s, Speed Index is 1.8 s (highlighted amber), Total Blocking Time is 20 ms, Largest Contentful Paint is 0.5 s and Cumulative layout shift is 0.17 (highighted amber)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rgtcyns4yvmnl1cukmia.png)

Another reason why I moved to Astro was to write the site in Svelte. So it would be nice to see how much of the speed pickup comes from Svelte and how much from partial hydration.

The <a aria-label="Read more about core web vitals" href="https://web.dev/vitals/">Core Web Vitals which are important to Google</a> for ranking are Largest Contentful Paint, First Input Delay and Cumulative Layout Shift.  Lighthouse does not measure First Input Delay, though <a aria-label="Read more about Total Blocking Time" href="https://docs.wp-rocket.me/article/1398-total-blocking-time-first-input-delay">improving Total Blocking Time can improve First Input Delay</a>.  The overall performance score is up from **92** to **100**.  Improvements come from Total Blocking Time dropping from **20&nbsp;ms** to **zero** as well as Time to Interactive and First Contentful Paint improvements.  Largest Contentful Paint is improved albeit by a 0.2 seconds.

### Why I moved to Astro: SEO Considerations

Perhaps it&rsquo;s just me, but overall the site feels faster and smoother.  This is possibly more important than the numbers, since at the end of the day the numbers are trying to model the &lsquo;feel&rsquo; of the site.  &lsquo;Feel&rsquo; is just a proxy for user experience and it is that which is most important for Search Engine Optimisation.

If you are interested in learning more about partial hydration there&rsquo;s already a <a aria-label="Learn about partial hydration in Astro" href="https://rodneylab.com/getting-started-astro">post on getting started with Astro</a>.

## 🐝 What's Next?

One drawback of Astro is that to get the most out of partial hydration I had to write blog posts in Astro.  I like MDX because I want easily to be able to put the content on developer <a aria-label="Open the Rodney Lab Dev To site" href="https://dev.to/askrodney">platforms like dev.to</a> and <a aria-label="Open the Rodney Lab hash node site" href="https://hashnode.com/@askRodney">Hashnode</a>.  Partly for that reason, but mostly for the experience, I wrote a <a aria-label="Open the c mess less Rodney Lab repo on Git Hub" href="https://github.com/rodneylab/cmessless">Rust MDX compiler which outputs Astro</a>.  I can write blog posts in MDX with the compiler running in watch mode to generate Astro as I type (or more accurately as I save).  This makes it easy to create pure Markdown posts for use on other platforms.  The other advantage is with Astro still in Beta, if the API changes, it is easy to take advantage of new features by updating the Rust compiler, instead of having to change individual posts.

I experimented with using Strapi as a CMS but preferred the overall experience and flexibility of writing in MDX (for this particular use case).  Having content in a database is convenient though, especially when it comes to generating JSON-LD markup for SEO, as an example.  The next step for the compiler would be to pull frontmatter off the Markdown source files and sync it to a PostgreSQL database.

### Svelte Animation

Svelte is awesome for animation, I must work a little Svelte animation into the site too!  Anyway the main aim was to get a new site built so I could start writing blog posts again, and at least Astro has done a fantastic job in helping to reach that goal!

## 🙏🏽 Why I moved to Astro: Feedback

Have you found the post useful? Would you prefer to see posts on another topic instead? Get in touch with ideas for new posts. Also if you like my writing style, get in touch if I can write some posts for your company site on a consultancy basis. Read on to find ways to get in touch, further below. If you want to support posts similar to this one and can spare a few dollars, euros or pounds, please <a aria-label="Support Rodney Lab via Buy me a Coffee" href="https://rodneylab.com/giving/">consider supporting me through Buy me a Coffee</a>.

Finally, feel free to share the post on your social media accounts for all your followers who will find it useful. As well as leaving a comment below, you can get in touch via <a aria-label="Message me on Twitter" href="https://twitter.com/messages/compose?recipient_id=1323579817258831875">@askRodney</a> on Twitter and also <a aria-label="Contact Rodney Lab via Telegram" href="https://t.me/askRodney">askRodney on Telegram</a>. Also, see <a aria-label="Get in touch with Rodney Lab" href="https://rodneylab.com/contact">further ways to get in touch with Rodney Lab</a>. I post regularly on <a aria-label="See posts on Astro" href="https://rodneylab.com/tags/astro/">Astro</a> as well as <a aria-label="See posts on svelte kit" href="https://rodneylab.com/tags/sveltekit/">SvelteKit</a>. Also <a aria-label="Subscribe to the Rodney Lab newsletter" href="https://rodneylab.com/about/#newsletter">subscribe to the newsletter to keep up-to-date</a> with our latest projects.