A Look at Building with Astro
Astro is a brand new framework for building websites. To me, the big thing is that it allows you to build a site like you’re using a JavaScript framework (and you are), but the output is a zero-JavaScript static site. You can opt-in to client-side JavaScript as needed, and there are clever options for doing so. Notably, the learning curve is somewhat flattened by the fact that it supports componentry you may already know: React/Preact (JSX), Svelte, Vue, or web components.
Table stakes
Starting a new project is as easy as it should be:
npm init astro npm install npm start
There is a helpful little process and output:
As expected (like you would get with Next or Nuxt or any other site builder kind of project) you get a dev server at a local port you can pop right up:
From here, I consider the table stakes to be CSS injection / Hot Module Reloading. No worries there:
A static site generator with honest-to-god real actual components
This is such a wonderful thing to me. I really like the idea of static site generators—I think they make a lot of sense in a lot of situations. Sending HTML over-the-wire is just a good move for resiliency, CDN-efficiency, SEO, accessibility, you name it. But in the past a lot of the options were either:
- A JavaScript powered static site generator, that does generate a “static” site, but also ships a JavaScript bundle (e.g. Next or Gatsby)
- A static site generator that is more focused on HTML and has its own templating/formats that aren’t JavaScript components (e.g. Eleventy or Jekyll)
I know there are exceptions, but this covers the vast majority of the site generator market.
But I want both!
- I want to craft sites from JavaScript-components, because the syntax and tooling around them is just better than any other component system we have right now.
- I want static output that is actually zero-JavaScript (unless I manually opt-in to things).
That’s what happens with Astro.
Those components?
- They can be .jsx files
- They can be .svelte files
- They can be .vue files
- These are “renderers” and you can BYO.
Astro also has it’s own format (.astro) and it’s also very compelling because:
- It’s obviously a first-class citizen of how Astro works
- It’s comfortably JSX-like…
- …except better because it does stuff like makes the work automatically
- Styled scoping works out of the box, through a normal