DEV Community

nedajahanfar
nedajahanfar

Posted on

Astro: A Different Kind of Web Framework

Astro first appeared in 2021 as a new kind of frontend framework, built with a very specific goal: giving developers complete control over how their websites are rendered.

Unlike many frameworks that push you into either SSR (server-side rendering) or CSR (client-side rendering / SPA), Astro lets you mix and match. This flexibility makes it especially powerful for content-heavy sites—think blogs, documentation, e-commerce catalogs—where most of the page is static but certain parts (like search bars, filters, or comments) still need to be dynamic.

The Island Architecture:
Astro’s secret sauce is what it calls “Island Architecture.”
Most of your site is rendered on the server by default (fast, SEO-friendly, lightweight).

But individual “islands” (small, interactive components) can be hydrated on the client only when needed.

This means you can have a mostly static site with a React search bar, a Vue shopping cart, and maybe a SolidJS widget—all living together on the same page.

Framework Flexibility:
Astro is framework-agnostic. You can use React, Vue, Svelte, Solid, Preact, Lit, or just plain HTML/JS. Or mix them all. That’s why Astro is often called a flexible framework: it doesn’t lock you in.
Each component you write can be given a client: directive to control when (and if) it loads on the browser:

client:load → load immediately.

client:visible → load only when it comes into view.

client:idle → wait until the browser is idle.

client:only="react" → load only in React, ignoring server-side rendering.

If you don’t specify anything, Astro takes a server-first approach—it behaves like SSR, sending down plain HTML without extra JavaScript.

File-Based Routing:

Astro also keeps things simple with file-based routing:
Put your pages inside the src/pages folder.
A file like about.astro becomes /about.
A folder with index.astro maps to /foldername.
Bracketed names (like [slug].astro) handle dynamic routes.

Inside each .astro file, the structure is straightforward:
Frontmatter (the top script block) → where you do imports and API calls.
Markup (HTML) → the actual page structure.
Style → scoped to that page or component.
Script → optional client-side JavaScript.

This encourages clean separation of logic and design.

Analogy :))

Think of Astro like building a theme park:

Most rides (pages) are already built and ready (static content rendered on the server).
But a few attractions (interactive islands) only start running when visitors walk up to them (hydrated when needed).
You, the architect, decide which rides are permanent and which ones only spin up when someone presses the button.

Top comments (0)