🐱‍🚀 What is Astro.js 🐱‍🚀
Tags: javascript, node, react, astro
Published: 2022-09-06 11:49:50


Astro is a tool for building static websites with your favorite JavaScript framework.

![Frameworks](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4pkxlh4j2dyol6i1ehvi.png)


But it will ship zero JavaScript to the browser 🤯.

End-users love fast-loading websites but developers love to build them with heavy JavaScript frameworks.

![Frameworks sizes](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1q7ron2rldc1fe1wdccq.png)


Astro allows you to build your website with your favorite framework and even multiple  frameworks at the same time.
Astro renders them to static HTML at build time, this sounds like a static site generator, but what it's unique here its, when you have a component that needs to be interactive with full JavaScript, you have multiple strategies to render and hydrate the client side.

### Welcome to Directives
Template directives are a special kind of HTML attribute available inside of any Astro component template (.astro files), and some can also be used in .mdx files.

Template directives are used to control an element or component’s behavior in some way

Here are some example for client directives.

`client:load` - Will be rendered with JavaScript on the initial the page load, it's like a normal JavaScript App.

`client:idle` - Will wait until the browser is idle to render it, this is used when the component is not a high priority. 

`client:visible` - Will be rendered until its visible to the end-user.

For more about client-directives [here](https://docs.astro.build/en/reference/directives-reference/#client-directives)

When using Atro we need to stop thinking that our website like SPA with JavaScript takes over everything, think like an archipelago, when the water is the static HTML and islands are self-contain components that ad interactivity when need it, the result is a fast website with the full interactive power of a framework.

![Islands](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5v0dkch16imfxf24pdnq.jpg)

_Picture Resource:_ https://www.nationalgeographic.com/travel/slideshow/paid-content-the-philippines-an-archipelago-of-unique-scenery


### Building your first Atro Project

`npm create astro@latest`


Inside the project, you will find the pages directory, here it's the router configuration of the website. Every page is defined as an Astro component, inside of it you can write static HTML or declare components that maybe be written in React/Vue or any framework. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t6igpuma0z1ondnrfmub.png)


On the top of the component, you will notice triple dashes, this is where you can execute JavaScript on the server at build time, here you can fetch data or local markdown data in your source code.


![Server Render](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h1ogw7vcv4koi9ztvwp7.png)


To add React to your website, follow the following steps from the official documentation [here](https://docs.astro.build/en/core-concepts/framework-components/).

![React Component](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gjuxf2cdhfe82oeh1hw5.png)


Resources:
- [Astro](https://astro.build/)
- [Islands Architecture](https://jasonformat.com/islands-architecture/)
- [Framework-components](https://docs.astro.build/en/core-concepts/framework-components/)
- [Client Directives](https://docs.astro.build/en/reference/directives-reference/#client-directives)