Why you should try Astro

Introduction

From the title of this article, you can probably tell that it is dedicated to recommending the web framework Astro.js🔗. This blog is currently built with Astro. I have been using it to create websites since before the stable release came out, and by now I have picked up a fair amount of experience with it. Since many people have also asked me about it, I decided to write this article to share my thoughts.

Before this, I had used many different frameworks, such as Next, Gatsby, Jekyll, and HUGO. They are all excellent frameworks, but none of them quite hit the mark for my needs. After using them, I always felt some degree of friction or regret. Let us first understand exactly what problems Astro solves so you can determine whether this framework is suitable for the project you have in hand.

Reasons to Use Astro

I think what Astro does best is its excellent developer experience. It is a framework that lets you “opt into complexity.” In a frontend environment where many meta-frameworks exist, you usually need to learn a framework in advance, such as React, Vue, Angular… and then get locked into that framework’s ecosystem, such as Next, Nuxt, or Analog. Alternatively, you may need to learn a template language such as Liquid or Go Template… or even a backend language 😣.

But in Astro, you still only need HTML, CSS, and JavaScript (or TypeScript if you prefer) to get started. If, like me, you are mainly a frontend engineer who wants to build mostly static websites, for example: marketing sites, documentation sites, blogs, portfolios… then Astro is an excellent choice, and the experience is genuinely great! You can start from a simple static web page and use the Islands architecture🔗 to extend the page’s capabilities with JavaScript while keeping the page highly performant.

Compared with other frameworks, its learning curve is very gentle. I can spend most of my effort on the content of the website rather than learning framework-specific rules. This is what I like most about Astro.

Reasons Not to Use Astro

If you expect to build a highly interactive web page that is more like an application, I would recommend using Next, Nuxt, or another framework. Astro.js’s architecture makes it naturally suited for generating static pages and selectively adding interactivity.

What Is Astro?

Astro is an all-in-one framework based on Vite🔗 (a modern build tool) and written in JavaScript. It is designed for creating fast, content-focused websites, with the following five characteristics🔗:

How Do You Use Astro?

Creating a Project

Before installing Astro, you will need to install Node.js🔗, and it must be at least version v16.12.0. I recommend using the official automated installation wizard, or you can also browse templates in your browser🔗:

Terminal window
npm create astro@latest

During the process, it will ask you for the project name, location, and template to use. After that, enter the project and run the npm run dev command to open the development server in your browser. All changes during development will be reflected there in real time.

Alternatively, you can use the build command npm run build to generate a static website. By default, the generated static files will be placed in the dist folder. You can use the preview command npm run preview to preview the currently generated static website.

Then you can start building your website 🥳

  • Add a framework: See our Integrations Guide (EN)🔗 to learn how to use npx astro add to extend Astro support for frameworks such as React, Svelte, and Tailwind.
  • Deploy your website: See our Deployment Guide🔗 to learn how to build and deploy an Astro project to the web.
  • Understand the codebase: See our Project Structure🔗 guide to learn more about the structure of an Astro project.

Conclusion

This article is just a starting point. I am preparing a more complete and practical project to explain how to use Astro, so stay tuned! While learning, I highly recommend the documentation from Astro itself🔗 as well as dedicated documentation AIs such as Houston AI🔗 and Rix Astro🔗.