High Performance in Front-end: My Experience Building with Astro and React

3 min

High Performance in Front-end: My Experience Building with Astro and React

Building a high-performance front-end has always been a challenge in web development. In my journey creating this blog, I discovered that combining Astro and React not only simplifies development but also delivers outstanding performance results. Let me share my experience and guide you through creating a similar blog.

Why Astro and React?

Astro stands out for its island architecture, which allows you to build fast websites by default. Unlike traditional frameworks that ship JavaScript to the client for everything, Astro renders components to HTML on the server and only hydrates interactive parts when needed.

React, on the other hand, provides a robust ecosystem for building complex user interfaces. When used strategically within Astro’s islands, React components become highly efficient.

Performance Benefits I Experienced

  • Faster initial load times: Astro’s static generation means pages load almost instantly
  • Smaller bundle sizes: Only ship JavaScript for interactive components
  • Better SEO: Server-side rendering ensures search engines see fully rendered content
  • Improved Core Web Vitals: Lighthouse scores consistently above 90

Step-by-Step Guide: Building Your Astro + React Blog

1. Project Setup

First, create a new Astro project with React integration:

npm create astro@latest my-blog
cd my-blog
npm install @astrojs/react react react-dom

2. Configure Astro

Update your astro.config.ts:

import { defineConfig } from 'astro/config';
import react from '@astrojs/react';
import mdx from '@astrojs/mdx';

export default defineConfig({
  integrations: [react(), mdx()],
  output: 'static',
});

3. Add TypeScript Support

Create a tsconfig.json:

{
  "extends": "astro/tsconfigs/strict",
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "react"
  }
}

4. Create Your Content Structure

Set up content collections for blog posts:

// src/content/config.ts
import { defineCollection, z } from 'astro:content';

const blog = defineCollection({
  type: 'content',
  schema: z.object({
    title: z.string(),
    published: z.date(),
    description: z.string(),
    tags: z.array(z.string()),
    lang: z.string(),
    abbrlink: z.string(),
  }),
});

export const collections = { blog };

5. Build Your Layout

Create a basic layout with React components:

---
// src/layouts/Layout.astro
const { title } = Astro.props;
---

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>{title}</title>
  </head>
  <body>
    <header>
      <h1>My Blog</h1>
    </header>
    <main>
      <slot />
    </main>
  </body>
</html>

6. Create Interactive Components with React

// src/components/Counter.tsx
import { useState } from 'react';

export default function Counter() {
  const [count, setCount] = useState(0);
  
  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </div>
  );
}

7. Add Performance Optimizations

Implement lazy loading and code splitting:

---
// Only hydrate this component when needed
---
<Counter client:load />

8. Internationalization (i18n)

For multi-language support, create language files:

// src/i18n/ui.ts
export const ui = {
  en: {
    'nav.home': 'Home',
    'nav.about': 'About',
  },
  pt: {
    'nav.home': 'Início',
    'nav.about': 'Sobre',
  },
};

Performance Tips from My Experience

  1. Use Astro islands wisely: Only make components interactive when necessary
  2. Optimize images: Use Astro’s built-in image optimization
  3. Implement caching: Use appropriate cache headers for static assets
  4. Minimize JavaScript: Avoid shipping unnecessary JS to the client
  5. Use modern formats: Serve WebP images and modern CSS

Conclusion

Astro and React together provide a powerful combination for building high-performance front-end applications. My experience with this blog has shown that with the right architecture, you can achieve excellent performance while maintaining developer experience.

Start small, focus on performance from the beginning, and scale as needed. Your users will thank you for the fast, responsive experience.

Have you tried Astro? Share your experiences in the comments!