Delivery
6 min
Astro is a tool known for making things easier by building a multi page application and shipping with no Javascript by default. Meaning, only the HTML file will be sent to the browser, with zero JS needed to get loaded on the browser and slow you down.
Instead of heavy interactive apps, Astro is designed to target content-based websites. Astro is a really great option for that, as much as we want to publish some content.
It's a kind of server-first, it privileges server-side rendering over client-side rendering as much as possible.
Astro was created for creating webpages with lots of content. This covers the majority of e-commerce sites, blogs, publishing sites, documentation sites, and blogs.
We need to know something crucial before beginning our review. The distinction between a web application and a website;
Having said this, you should be aware that Astro might not be the ideal option for your project if you're trying to build a web application.
For your web application-focused project, exploring over Next.js framework as an option would be more appropriate in your situation.
Astro team made sure we can utilize any favorite UI component language that we already are familiar with. Frameworks such as Svelte, React, Vue, Lit, Solid, etc. are compatible for creating new UI components in Astro projects.
All web developers should be able to use Astro, this is what the team behind Astro had in ming. Regardless your previous web development expertise or skill level, Astro is built with an easy to use approach.
The concept of partial hydration allows developers to determine what aspects are loaded and when, in order to provide fast interactivity. This is done by being able to put some client-side JS only where it is needed using something referred as "island architecture".
Partial hydration definitely is a wise and practical strategy. Our webpage initially is sent as pure HTML from the server to the client. JavaScript is not shipped by default.
However, we know that JavaScript is what makes our page interactive. This is where hydration comes into play as the procedure of loading JavaScript.
Hydration is cool, it’s in place only when we need it, for example, if we have a page that starts with content that doesn’t need interaction, javascript is not needed.
So we load nothing, but if scroll down to the footer when we have a form-contact that need interaction with the user, here the hydration comes in place to hydrate our page with the javascript needed for the form.
The guiding principle of Astro is to build Islands of Interactivity that the browser can hydrate on its own. Astro Island is the solution.
We can optimize how the page loads javascript by treating each component (Island) independently.
We divide the page into multiple components, each element has its own case. Image carousels need javascript, text or image doesn’t need it, a comment section needs javascript, and so on.
We load the javascript only if the element appears, if not we load nothing.
The Islands' design incorporates principles from several rendering approaches, including server-side rendering, static site generation, and partial hydration.
The following are some of the major advantages of integrating islands:
Some disadvantages:
Astro is unique in that it is both a static site generator and strives to keep JavaScript out of the final build as much as possible. It also prefers multi-page apps over single-page apps (SPAs).
A website may be built in a variety of ways. The Single Page Applications (SPAs) concept promoted by Angular and React, has mostly overtaken MPAs, but Multi-Page Applications (MPAs) are making a comeback due to the amount of Javascript we transport to the browser using SPAs.
Fast startup is crucial for many websites, for many sites and apps with little interactivity, a client-rendered framework like Angular is overkill.
This generation of MPAs is distinct from earlier generations. Astro has a component-based approach employing the island's architecture.
SSR is an abbreviation for Server-Side Rendering, which is a rendering approach that turns our application into HTML on the server.
Unlike typical SPAs that utilize CSR (client side rendering) to display their content, SSR provides a faster "time-to-content" and is better for SEO.
There are a lot of frameworks that are already implementing the principe of SSR, like Next.js, and Gatsby. Astro has a different approach to the implementation, according to their documentation it’s created to operate on a server.
---
const dateCreation = 2010;
---
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Astro Playground</title>
<style>
header {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
margin-top: 15vh;
font-family: Arial;
}
.note {
margin: 0;
padding: 1rem;
border-radius: 8px;
background: #E4E5E6;
border: 1px solid #BBB;
}
</style>
</head>
<body>
<header>
<img width="60" height="80" src="<https://assets.website-files.com/6029242da9cc79f23dc41aeb/602d5b26c08ffe20eaf4a740_Adservio-Icon-Big.svg>" alt="Astro logo">
<h1>Adservio</h1>
<p class="note">
<strong>FOUNDED IN:</strong><br/>
{dateCreation}
</p>
</header>
</body>
</html>
Page Rendered:
A lot of specialists in the field believe that Astro may probably completely change how websites are built.
The fact of not using javascript will have a major impact on the performance, it will be for sure excellent, not only that, but also maintaining a codebase can be simple enough for everyone.