Fireship · @fireship
Astro in 100 Seconds
Uploaded July 15, 2021 · Length 2:17
Summary
Astro builds fast, SEO-friendly websites with JavaScript frameworks while shipping zero JavaScript to the browser.
- astro
- static website
- javascript frameworks
- zero js
- static site generator
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
Astro, a tool for building static websites with your favorite JavaScript frameworks while
- 0:05
shipping zero JavaScript to the browser.
- 0:08
End users love a fast-loading website, but developers love to build them with big, heavy
- 0:12
frameworks.
- 0:13
Unfortunately, the key to better performance is to use less JavaScript.
- 0:17
Astro allows you to build a site with your favorite framework or even multiple frameworks
- 0:22
at the same time, and renders them to static HTML at build time.
- 0:26
That sounds like a static site generator, but what's unique is that when you have a
- 0:29
component that needs to be fully interactive with JavaScript, you have multiple strategies
- 0:33
at your disposal to render and hydrate it client-side.
- 0:37
Any component in your UI with the client load directive will be rendered with JavaScript
- 0:41
on the initial page load like normal.
- 0:43
But if the component is not a high priority, you can wait until the browser is idle before
- 0:47
rendering it.
- 0:48
Or if it's a component that's further down the page, you can hold off on rendering it
- 0:52
until it's visible to the actual user with IntersectionObserver.
- 0:56
Instead of thinking of a website as a single-page application where the JavaScript takes over
- 0:59
everything think of it as an archipelago where your water is the static HTML and islands are self components that add interactivity when needed The end result is a website that is fast and search engine friendly but also has the full interactive power of a front framework To build your first project open an empty directory
- 1:17
and run npm init astro. Inside the project, you'll find the pages directory. The file structure here
- 1:23
defines the actual URL structure or routing configuration for your website. Each page is
- 1:28
defined as an astro component, inside of which you can write static HTML, while also declaring
- 1:33
components that might be written in React, Vue, or Svelte. At the top of a component, you'll notice
- 1:38
triple dashes. This is where you can execute JavaScript on the server at build time. You may
- 1:43
want to fetch data from your server or content management system, or local markdown files in
- 1:48
your source code. And as an added bonus, it supports top-level await here, making it easier
- 1:52
to write clean code. And finally, you can expect all of the essential features found in other static
- 1:57
site generators, like RSS feeds, sitemaps, and so on.


