How to start with Astro.build
What is Astro.build?
Astro is an all-in-one web framework for building fast, content-focused websites. Astro optimizes your website as no other framework can do. Leverage Astro’s unique zero-JS front-end architecture to unlock higher conversion rates with better SEO.
Is Astro.build really that fast?
I created a page with a header and a few blocks. Two of those blocks are getting data from API and here is a view how it looks like:
Well, it’s pretty fast. But now the funny part: Astro.build developers still need to finish making it faster as they plan to improve speed even more in the future!
That’s even faster than Next or Gatsby!
What can I do with Astro?
Astro is an all-in-one web framework, so you can do everything with that. Create Astro project with CMS, sure, no problem, here is a list of all CMS that Astro is compatible with, Create components as Reat or Vue components, sure, import it to the main Astro file, Astro also have SSR rendering, its very similar to next.js, but its faster. With Astro, you can use every tool you use to work.
Why is Astro that/so fast?
The critical thing about Astro is that the components you create to work with Astro work as Astro-islands. The term “Astro Island” refers to an interactive UI component on an otherwise static page of HTML. Multiple islands can exist on a page, and an island always renders in isolation. Think of them as islands in a sea of static, non-interactive HTML.
In Astro, you can use any supported UI framework (React, Svelte, Vue, etc.) to render islands in the browser. You can mix and match different frameworks on the same page, or pick your favorite. The technique that this architectural pattern builds on is known as partial or selective hydration. Astro leverages this technique behind the scenes, powering your islands automatically.
Partial hydration is a way to display our components. We can decide how we want to show the scripts. Let’s make an example to see how it works:
So let’s create a simple button with props and import it as a regular component:
Our added button is at the end of the page. This button has some styles and functions, which you can see on console.log on the right part of the screenshoot. So what will happen when we click on this button? Nothing, the button won’t work. But more important question is: why is this happening? Have I done something wrong? No, everything is fine. That is why we haven’t said Astro how we want to display scripts for this component.
First, you will need an extension for your code editor. If you use Visual studio code, go to the plugins page and type Astro, then download this plugin, then go back to code and just type client: in your component, and there you will have a list of options to choose:
<span style="font-size: 1.8rem;"><Button client:media="(max-width: 500px)" /></span>
- Only: skips HTML server rendering, and renders only on the client
- Visible: when you see this component on your screen, then this component will get scripts that we write in component
This is how you can create your components in Astro. This solution is very powerful and that one and the other features, which are in Astro, give a big advantage when we compare it to the other tools.
If I haven’t convinced you to start using Astro yet, then
- Content-focused: Astro was designed for content-rich websites.
- Server-first: Websites run faster when they render HTML on the server
- Fast by default: Building a slow website in Astro should be impossible.
- Easy to use: You don’t need to be an expert to build something with Astro.
- Fully-featured but flexible: Over 100+ Astro integrations to choose from.
So let’s type npm create astro@latest in your code editor console, and have fun!
Remember Astro documentation!
Astro is a potent tool that is easy to use, so you must check! With many options, a massive plus for Astro for that you can use multiple frameworks together! Also, Astro will improve your development experience, and you won’t regret checking it out!
If you have any questions, give us a shout. Our developers are here to assist you.