Every few years the pendulum swings between “ship everything as JavaScript” and “ship as little JavaScript as possible”. For content sites (blogs, portfolios, docs, marketing pages) the second camp has clearly won, and Astro is the sharpest tool in it.
This post is the playbook I use on every content site I build. None of it is exotic. The boring techniques, applied consistently, get you to a Lighthouse 100 that stays at 100 after the marketing team adds their fourth embed.
The islands model, briefly
Astro renders your entire page to static HTML at build time. Components that need interactivity opt in explicitly:
---import Chart from '../components/Chart.tsx';---
<!-- Rendered to HTML, zero JS shipped --><h1>Traffic report</h1>
<!-- Hydrated only when it scrolls into view --><Chart client:visible />Everything else (headers, footers, article bodies, cards) ships as plain HTML and CSS. The result is that your baseline JavaScript cost is close to zero, and every kilobyte you do ship is a deliberate decision.
Measure before you optimize
Before touching anything, get a baseline you can trust. Lab numbers from your laptop lie. I use three sources:
| Source | What it tells you | When to check |
|---|---|---|
| Lighthouse (CI) | Regressions between commits | Every pull request |
| WebPageTest, 3G/Moto | What a real slow device experiences | Before and after a change |
| CrUX / field data | What your visitors actually experienced | Monthly |
The field data is the one that counts. A site can score 100 in the lab and still have a poor Largest Contentful Paint (LCP) in the field because the hero image is served from an origin two continents away.
# One-off lab run with a throttled mobile profilenpx lighthouse https://example.com --preset=perf --form-factor=mobile --throttling-method=simulateTechniques that actually move the needle
1. Prefetch on hover and viewport
Astro’s built-in prefetch turns full page loads into near-instant navigations:
export default defineConfig({ site: 'https://example.com', prefetch: { prefetchAll: true, defaultStrategy: 'viewport', },});By the time a visitor clicks a link, the next page’s HTML is usually already in the cache. You get SPA-feeling navigation without a router, a hydration step, or a client-side state bug budget.
2. Self-host your fonts
A @fontsource import costs one line and removes an entire third-party origin:
npm install @fontsource-variable/interpnpm add @fontsource-variable/interbun add @fontsource-variable/inter@import '@fontsource-variable/inter';No connection setup to fonts.googleapis.com, no layout shift from late-loading fonts, no consent-mode headaches. Variable fonts mean one file covers every weight you use, and the package ships unicode-range subsets so a Latin-only page never downloads Cyrillic glyphs.
Then preload the one file that matters for first paint:
---import inter from '@fontsource-variable/inter/files/inter-latin-wght-normal.woff2?url';---
<link rel="preload" href={inter} as="font" type="font/woff2" crossorigin />That single tag moves the font request from “after CSS is parsed” to “in parallel with CSS”. On a throttled connection it is worth 200–400ms of LCP.
3. Optimize the images you forgot about
Hero images get attention; the avatar in your footer doesn’t. Audit with the network tab sorted by size. The offenders are rarely where you expect.
Astro’s image pipeline handles the mechanical part. Keep images next to your content, reference them in frontmatter, and let the build produce the sizes:
---import { Image } from 'astro:assets';---
<Image src={post.data.image} alt="" widths={[720, 1080, 1440]} sizes="(min-width: 768px) 704px, calc(100vw - 2.5rem)" loading="eager" fetchpriority="high"/>Three rules that cover 95% of cases:
- Explicit dimensions everywhere. The browser reserves space before the image arrives, so nothing jumps.
loading="eager"+fetchpriority="high"on the LCP image only. Everything below the fold is lazy.- WebP by default, AVIF when the build budget allows. The compression gap between PNG and WebP for screenshots is routinely 10×.
4. Ship CSS, not a CSS runtime
Tailwind 4 compiles to a single stylesheet with only the classes you use. On this site that is around 13KB gzipped for every page, cached once. Compare that with a CSS-in-JS runtime that has to execute before it can paint anything.
The second half of this rule: avoid @import chains at runtime. One stylesheet, preloaded by the HTML parser, beats five small ones discovered one after another.
5. Keep third-party scripts off the critical path
Analytics, comments, embeds: each one is a negotiation. My defaults:
| Script type | Strategy |
|---|---|
| Analytics | defer, or a server-side proxy with no client script |
| Comments (giscus) | Lazy-load when the section scrolls into view |
| Video embeds | Static thumbnail; load the player on click |
| Chat widgets | Don’t |
If a script cannot be deferred, it needs a written justification. That sounds bureaucratic until the fourth marketing tag shows up.
What I stopped worrying about
- Client-side routing. Prefetched MPA navigation is indistinguishable for content sites.
- Skeleton screens. If the page renders in under 100ms, a skeleton is just a flash of fake content.
- Complex state management. Static pages don’t have state. This is a feature.
- Service workers. The HTTP cache plus prefetch covers the realistic cases, with none of the update-staleness bugs.
The scoreboard
This theme, the one you’re reading, ships roughly 5KB of JavaScript on a typical page: the theme toggle, mobile navigation, and a lazily-loaded search index. The rest is HTML, one stylesheet, and two self-hosted fonts.
| Metric | Before (SPA rewrite) | After (Astro) |
|---|---|---|
| JavaScript per page | 284 KB | 5 KB |
| Largest Contentful Paint | 2.9 s | 0.4 s |
| Total Blocking Time | 410 ms | 0 ms |
| Lighthouse performance | 71 | 100 |
Lighthouse gives it a 100 in every category, and more importantly, it feels instant on a mid-range Android phone over a mediocre connection, which is where most of the web actually lives.
