Back to Blogs
Web Development

Getting Started with Astro: Building Fast Modern Websites

2025-02-15
8 min read
Written by Adi Aulia Rahman
#Astro #Web Development #JavaScript #Tutorial

Introduction to Astro

Astro is a modern static site builder that delivers lightning-fast performance with a modern developer experience. Unlike traditional JavaScript frameworks, Astro ships zero JavaScript by default, resulting in incredibly fast page loads.

Why Choose Astro?

  • **Zero JavaScript by default**: Astro strips away unused JavaScript, shipping only HTML and CSS
  • **Framework agnostic**: Use React, Vue, Svelte, or any framework you prefer
  • **Islands Architecture**: Interactive components only hydrate when needed
  • **Content-focused**: Perfect for blogs, documentation, and portfolio sites
  • Setting Up Your First Project

    Getting started with Astro is straightforward. Open your terminal and run:

    ```bash

    npm create astro@latest my-blog

    cd my-blog

    npm run dev

    ```

    This will scaffold a new Astro project with all the essential files and configurations.

    Project Structure

    ```

    my-blog/

    ├── src/

    │ ├── components/

    │ ├── layouts/

    │ ├── pages/

    │ └── styles/

    ├── public/

    ├── astro.config.mjs

    └── package.json

    ```

    Creating Your First Page

    Astro uses file-based routing. Create a file in the `src/pages/` directory, and it automatically becomes a route:

    ```astro

    ---

    // src/pages/index.astro

    import Layout from '../layouts/Layout.astro'

    const title = "My First Astro Blog"

    ---

    Welcome to My Blog

    This is my first Astro page!

    ```

    Working with Components

    Astro components are reusable UI units. Here's how to create a blog card component:

    ```astro

    ---

    // src/components/BlogCard.astro

    interface Props {

    title: string

    excerpt: string

    date: string

    }

    const { title, excerpt, date } = Astro.props

    ---

    {title}

    {excerpt}

    ```

    Deploying Your Site

    Astro sites can be deployed to various platforms:

  • **Vercel**: `npm run build` outputs static files
  • **Netlify**: Drag and drop the `dist/` folder
  • **GitHub Pages**: Use GitHub Actions for automatic deployment
  • Conclusion

    Astro provides an excellent balance between developer experience and performance. By shipping less JavaScript and focusing on content, your websites load faster and provide better user experiences.

    Start building with Astro today and experience the difference!