DEV Community

Arhan Khan
Arhan Khan

Posted on

Astro for Beginners: Build Fast Websites With Almost No JavaScript

Astro is a web framework that builds websites which ship almost no JavaScript to the browser by default. If you have ever opened a simple blog or docs site and wondered why it needed a huge JavaScript bundle, Astro is the answer to that frustration.

How does Astro work? You write pages with components, just like in React or Vue, but Astro renders them to plain HTML on the server at build time. JavaScript is only sent to the browser for the parts you explicitly mark as interactive. A static blog built with Astro can load with zero JavaScript at all.

---
// This runs at build time, on the server
const posts = await Astro.glob('../posts/*.md');
const title = 'My Blog';
---

<html>
  <head><title>{title}</title></head>
  <body>
    <h1>{title}</h1>
    <ul>
      {posts.map((post) => (
        <li><a href={post.url}>{post.frontmatter.title}</a></li>
      ))}
    </ul>
  </body>
</html>
Enter fullscreen mode Exit fullscreen mode

Astro is great for beginners because it lets you use the tools you already know. You can write components in React, Vue, Svelte, or plain HTML, and mix them in the same project. The file-based routing is simple: a file in src/pages/ becomes a page on your site, no router config needed.

npm create astro@latest
cd my-site
npm run dev
Enter fullscreen mode Exit fullscreen mode

When should you use Astro? For blogs, documentation sites, portfolios, landing pages, and marketing sites — anything that is mostly content. If your site is a dashboard or an app where almost everything is interactive, a framework like Next.js or SvelteKit may fit better, because Astro's strength is shipping less JavaScript, not managing complex client state.

The limits are worth knowing. Astro is a build-time framework, so pages are generated when you build, not per request — for content that changes every second, you will need server rendering or client-side fetching. The ecosystem is smaller than React's, so you may occasionally miss a ready-made plugin.

Start today: create an Astro project, make a page with a list of your three favourite books, and check the built HTML in your browser's dev tools. Seeing a complete page with no JavaScript bundle is the moment the idea clicks.

Top comments (0)