Astro Framework

Astro Framework Cover
July 17, 2023

Astro is an open-source Framework that prioritizes speed and flexibility. It allows you to build websites quickly and efficiently. Astro integrates seamlessly with your favorite UI components and libraries, providing a comprehensive development experience.

The framework is inspired by the Islands Architecture, the framework supports various UI integrations, including React, Svelte, Vue, and potentially others. One notable contribution of Astro is its role in popularizing concepts like partial hydration and the idea of “Islands of Interactivity” within the web development community.

Performance and better SEO

One of Astro key strengths is its ability to optimize websites for speed. Astro lets you only add Javascript to the components that need it, which ensures that your website performs exceptionally well, leading to higher conversion rates and improved search engine optimization (SEO).

This is a comparison of performance between Astro and other frameworks using the lighthouse tool.

Web Frameworks Chart

The full post here.

Partial hydration

Partial hydration is a technique used in web development to optimize the rendering and interactivity of web pages. It involves selectively hydrating or initializing only the necessary parts of a web page with JavaScript while leaving the rest of the page as static content. Astro uses this technique, for example, you compose your UI components using your favorite JS web Framework Astro will render your entire site to static HTML during the build. So the result is a fully static website with all Javascript removed.

Client directives

Using the client’s directive we can control the hydration. With Astro, we have a property (client:*) to tell Astro how a component will be rendered.

The options available are (Each value will have a priority):

  • For higher priority, immediately-visible UI elements need to be interactive as soon as possible.<Component client:load />
  • For lower-priority UI elements that don’t need to be immediately interactive.<Component client:idle />
  • For low-priority UI elements that don’t need to be immediately interactive, will be hydrated until is visible in the viewport<Component client:visible />
  • For low-priority UI elements, this directive hydrates the element when is visible on certain screen sizes.<Component client:media=”(max-width: 50em)” />
  • With this directive, the component will be hydrated on page load but just on the client side, in a build time will be ignored.<Component client:only=”react” />

Content Management with Astro

In terms of content management, Astro is designed to accommodate a variety of needs. It offers flexibility in fetching data from any CMS (Content Management System) of your choice. Additionally, you can work locally with type-safe Markdown and MDX APIs, allowing you to create content in a familiar and structured manner. This content-focused approach ensures that Astro caters to your specific content requirements while maintaining a streamlined development workflow.

About Community

The Astro community is very big and active, you can find channels in Discord, and there are many themes and templates available created by the community, furthermore, as tools that you can integrate easily, the Astro ecosystem is increasing over time thanks to the community.