Build Fast & Modern Websites with Astro
A presentation by Tri Hargianto
Visit trihargianto.com to know me more
Astro is the web framework for building
content-driven
websites like blogs, marketing, and e-commerce.
For fast-loading and SEO-friendly web, choose Astro
Astro prioritizes
sending JavaScript only when necessary, resulting in lighter and faster-loading pages.
<html>
<body>
</body>
</html>
Hydration is like watering the βdryβ HTML with the βwaterβ of interactivity and event handlers.
Dan Abramov
Entire page is hydrated at once, meaning that JavaScript runs across all components
βeven those that
donβt need interactivity
$ pnpm create astro@latest
Put your *.astro
files inside ./src/pages
folder
<!-- src/pages/index.astro -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>Homepage</title>
</head>
<body>
This is the astro homepage
</body>
</html>
File | URL |
---|---|
./src/pages/about.astro |
/about |
./src/pages/profile.astro |
/profile |
./src/pages/contact.astro |
/contact |
Put your *.md
files inside ./src/pages
folder
---
title: Homepage
---
# Welcome to Astro
This is the Astro homepage created with Markdown.
File | URL |
---|---|
./src/pages/about.md |
/about |
./src/pages/profile.md |
/profile |
---
const type = "button";
---
<Button type={button}>
</Button>
---
import Button from '../components/Button.astro';
---
<Button>Click Me</Button>
---
const { variant } = Astro.props;
---
<Button class={`button ${variant}`}>
<slot />
</Button>
---
import Button from '../components/Button.astro';
---
<Button variant="primary">Primary Button</Button>
<Button variant="secondary">Secondary Button</Button>
<Button class="button">
<slot />
</button>
Create the css file
/* src/styles/global.css */
body {
font-family: Arial, sans-serif;
}
Import the CSS file
---
import '../styles/global.css';
---
Install TailwindCSS via Terminal
$ pnpm install tailwindcss
Import in src/styles/global.css
@import "tailwindcss";
Use it in your Astro file
TailwindCSS Styled Div
<html>
<body>
Header Content
</body>
</html>
---
import BaseLayout from '../layouts/BaseLayout.astro';
---
<BaseLayout>
Welcome to Astro
</BaseLayout>
<script>
Welcome to Astro
0
Install React
$ pnpm astro add react
Install Vue
$ pnpm astro add vue
Install Svelte
$ pnpm astro add svelte
---
import ReactCounter from '../components/ReactCounter.jsx';
---
<ReactCounter />
Don't forget to put client directive to make it interactive!
---
import ReactCounter from '../components/ReactCounter.jsx';
---
<ReactCounter client:idle />
---
import ReactCounter from '../components/ReactCounter.jsx';
import VueCounter from '../components/VueCounter.vue';
import SvelteCounter from '../components/SvelteCounter.svelte';
---
<ReactCounter client:idle />
<VueCounter client:idle />
<SvelteCounter client:idle />
What Astro suitable at
Ideal for news sites, blogs, documentation, and portfolios that prioritize content and fast load times.
Astro is better suited for websites with
light interactivity
rather than applications that demand complex real-time
interactions.
Any questions?