Astro, Next.js, and Gatsby are tools to build websites. They help make sites fast and easy to manage.
You want a simple blog or portfolio site that loads very fast.
You need a full website with server-side features and API routes.
You want to build a site with lots of pre-built pages and fast loading.
You want to use React components but also want good SEO and speed.
You want to mix different frontend frameworks in one project.
Syntax
Astro
Astro, Next.js, and Gatsby each have their own way to create pages and components.
Astro example page:
---
---
<h1>Hello from Astro</h1>
Next.js example page:
export default function Home() {
return <h1>Hello from Next.js</h1>
}
Gatsby example page:
import React from'react'
export default function Home() {
return <h1>Hello from Gatsby</h1>
}
Astro uses .astro files with HTML-like syntax and supports multiple frameworks.
Next.js uses React components and supports server-side rendering and API routes.
Examples
Astro page with simple HTML inside a .astro file.
Astro
---
---
<h1>Astro Page</h1>
Next.js page as a React component.
Astro
export default function Home() {
return <h1>Next.js Page</h1>
}
These are simple home pages for each framework showing their basic page structure.
Astro
// Astro example: src/pages/index.astro
---
---
<h1>Welcome to Astro</h1>
<p>This site loads fast by default.</p>
// Next.js example: pages/index.js
export default function Home() {
return (
<>
<h1>Welcome to Next.js</h1>
<p>This site supports server-side rendering.</p>
</>
)
}
// Gatsby example: src/pages/index.js
import React from'react'
export default function Home() {
return (
<>
<h1>Welcome to Gatsby</h1>
<p>This site uses static site generation.</p>
</>
)
}
OutputSuccess
Important Notes
Astro focuses on shipping less JavaScript by default, improving speed.
Next.js is great for apps needing dynamic data and API routes.
Gatsby is strong for static sites with lots of content and plugins.
Summary
Astro is best for fast, simple sites with mixed frameworks.
Next.js is best for dynamic React apps with server features.
Gatsby is best for static content-rich sites with React.
Practice
(1/5)
1. Which framework is best suited for building a fast, simple website that can use components from multiple frontend frameworks?
easy
A. Gatsby
B. Next.js
C. Astro
D. Vue.js
Solution
Step 1: Understand Astro's main feature
Astro is designed to build fast, simple sites and supports using components from different frontend frameworks together.
Step 2: Compare with Next.js and Gatsby
Next.js focuses on dynamic React apps with server features, and Gatsby is for static React content sites, so they don't emphasize mixed frameworks.
Final Answer:
Astro -> Option C
Quick Check:
Fast, simple, mixed frameworks = Astro [OK]
Hint: Astro = fast + mixed frameworks [OK]
Common Mistakes:
Confusing Next.js as supporting multiple frameworks
Thinking Gatsby supports mixed frameworks
Choosing Vue.js which is not part of the comparison
2. Which of the following is the correct way to describe Next.js?
easy
A. A React framework with server-side rendering and API routes
B. A CSS framework for styling React apps
C. A tool for building websites using multiple frontend frameworks
D. A static site generator focused on markdown content
Solution
Step 1: Identify Next.js features
Next.js is a React framework that supports server-side rendering and API routes for dynamic apps.
Step 2: Eliminate incorrect options
A static site generator focused on markdown content describes Gatsby more closely, a CSS framework for styling React apps is unrelated, and a tool for building websites using multiple frontend frameworks describes Astro.
Final Answer:
A React framework with server-side rendering and API routes -> Option A
3. Given the following scenario: You want to build a blog with lots of static content and React components. Which framework will generate a fully static site optimized for fast loading?
medium
A. Astro
B. Gatsby
C. Next.js
D. Express.js
Solution
Step 1: Identify Gatsby's strength
Gatsby is known for generating static sites optimized for content-rich blogs using React components.
Step 2: Compare with other frameworks
Astro is fast but focuses on mixed frameworks, Next.js supports dynamic server features, and Express.js is a backend framework, not for static sites.
Final Answer:
Gatsby -> Option B
Quick Check:
Static React blog = Gatsby [OK]
Hint: Static React content = Gatsby [OK]
Common Mistakes:
Choosing Next.js for static-only sites
Confusing Astro's mixed framework support with Gatsby
Selecting Express.js which is backend only
4. You wrote a Next.js app but your API routes are not working as expected. Which of the following is a common mistake that could cause this issue?
medium
A. Placing API route files outside the /pages/api directory
B. Using Astro components inside API routes
C. Using Gatsby plugins in Next.js config
D. Not importing React in every component
Solution
Step 1: Understand Next.js API route structure
API routes must be inside the /pages/api directory to work correctly in Next.js.
Step 2: Identify common mistakes
Placing API files elsewhere will cause routes not to work. Using Astro components or Gatsby plugins is unrelated to API routes. React import is automatic in Next.js 17+.
Final Answer:
Placing API route files outside the /pages/api directory -> Option A
Quick Check:
API routes must be in /pages/api [OK]
Hint: API routes go in /pages/api folder [OK]
Common Mistakes:
Putting API files in wrong folders
Mixing plugins from other frameworks
Assuming React import is always needed
5. You want to build a website that loads very fast, uses React components, and also includes some Vue components. Which framework should you choose and why?
hard
A. Create React App, because it supports Vue components
B. Gatsby, because it is optimized for React and static content
C. Next.js, because it supports multiple frontend frameworks natively
D. Astro, because it allows mixing React and Vue components with fast loading