09:41:00

Astro and Zero JavaScript: Why It Fits Landing Pages, Blogs, and Content Sites

How Astro ships HTML first and JavaScript only where you ask for it, and how to decide when that approach beats a full single-page application.

Published
Reading time
8 min read
  • astro
  • performance
  • landing-page
On this page

Most pages on the web are documents. A landing page explains a product, a blog post tells a story, a portfolio shows work. They need to be fast, readable, and indexable, and they rarely need a client-side framework running the whole page.

Yet many of these pages are built as single-page applications, which means the visitor downloads, parses, and executes a large amount of JavaScript before seeing something that could have been plain HTML.

Astro starts from the opposite assumption: render to HTML at build time, and ship no JavaScript unless a component asks for it.


What "Zero JS by Default" Means

When you build an Astro page, components render to static HTML on the server or at build time. The framework itself is not sent to the browser. A page made of Astro components and Markdown produces markup and CSS, and nothing else.

astro
---
// This code runs at build time and never reaches the browser
import Layout from '../layouts/Layout.astro'
import { getCollection } from 'astro:content'

const posts = await getCollection('blog')
---

<Layout title="Latest articles">
  <h1>Latest articles</h1>
  <ul>
    {posts.map((post) => (
      <li><a href={`/blog/${post.id}`}>{post.data.title}</a></li>
    ))}
  </ul>
</Layout>

The result is a page that paints as soon as the HTML arrives. There is no hydration step, so there is nothing to wait for before links and text are usable.

This is the main reason Astro tends to do well on Core Web Vitals for content-driven pages: less JavaScript on the main thread means less delay before the page responds to input.


Islands: Adding Interactivity Only Where It Is Needed

Real pages still contain interactive parts: a pricing toggle, a carousel, a search box. Astro handles this with islands. An interactive component is hydrated independently, while the rest of the page stays static HTML.

You choose how and when each island loads with a client directive:

Directive When the component hydrates
client:load Immediately on page load
client:idle When the browser is idle
client:visible When the component scrolls into view
client:media When a media query matches
client:only On the client only, with no server render
astro
---
import PricingToggle from '../components/PricingToggle.vue'
import ReviewsCarousel from '../components/ReviewsCarousel.tsx'
---

<!-- Needed straight away: hydrate on load -->
<PricingToggle client:load />

<!-- Below the fold: hydrate only when the visitor scrolls to it -->
<ReviewsCarousel client:visible />

Because islands are independent, you can even mix frameworks on one page: a Vue component next to a React component. In practice, most teams pick one and use islands to limit how much of it ships.


Plain Scripts Are Often Enough

A surprising amount of landing-page interactivity does not need a framework. A mobile menu, an accordion, a theme toggle, and scroll-triggered animation can all be a short script. Astro bundles the <script> tags inside components and loads them as modules:

astro
<button id="menu-toggle" aria-expanded="false">Menu</button>
<nav id="menu" hidden>...</nav>

<script>
  const toggle = document.getElementById('menu-toggle')
  const menu = document.getElementById('menu')

  toggle?.addEventListener('click', () => {
    const open = toggle.getAttribute('aria-expanded') === 'true'
    toggle.setAttribute('aria-expanded', String(!open))
    menu?.toggleAttribute('hidden', open)
  })
</script>

This keeps the interactive part tiny, and it keeps the markup accessible because it is real HTML first.


Why It Suits Landing Pages

A landing page has a clear job: load quickly, communicate one message, and get the visitor to act. Astro supports that job in several ways.

  • Fast first paint. HTML and CSS arrive ready to render, which helps largest contentful paint.
  • SEO friendly. Content is in the HTML that crawlers receive, with no dependence on client-side rendering.
  • Image optimization built in. The astro:assets helpers resize images, emit modern formats, and set dimensions to avoid layout shift.
  • Content collections. Blog posts and case studies live as Markdown with a typed schema, validated at build time.
  • Simple hosting. The output is static files, which any CDN can serve cheaply.
  • Smooth navigation when you want it. The client router adds animated page transitions on top of normal multi-page navigation, without turning the site into a single-page app.

Keeping a Site Truly Light

Starting with no JavaScript does not guarantee it stays that way. A few habits protect the advantage:

  1. Default to static. Add an island only when a component genuinely needs state or events.
  2. Choose the loosest directive that works. client:visible and client:idle defer cost that client:load pays immediately.
  3. Watch third-party scripts. Analytics, chat widgets, and tag managers often outweigh the entire site. Load them late, or use a worker-based approach.
  4. Measure. Run Lighthouse and look at the total JavaScript transferred, not only the score.
  5. Preload only what is critical. Fonts and the largest image above the fold are good candidates. Everything else can wait.

When Astro Is Not the Right Tool

Zero JavaScript is a strength for documents and a poor fit for applications. If most of the page is interactive, and state is shared across many components, a framework-driven app is simpler to build and reason about.

A rough guide:

  • Choose Astro for landing pages, marketing sites, documentation, blogs, portfolios, and catalogues where content dominates.
  • Choose a full framework such as Next.js or Nuxt for dashboards, editors, and products where the interface is the application.
  • Mix them when needed: an Astro shell with a few framework islands often gives most of the benefit of both.

Takeaway

Astro changes the default. Instead of paying a JavaScript cost on every page and optimizing it down, you pay nothing and add cost deliberately. For landing pages and content sites, that default matches what the pages actually are, and it is why a well-built Astro site can feel instant without exotic tuning.

  • #astro
  • #performance
  • #landing-page
  • #islands

Share

Comments

Join the conversation

Sign in with GitHub to leave a comment on Astro and Zero JavaScript: Why It Fits Landing Pages, Blogs, and Content Sites.

Pip · Personal AI assistant

What would you like to know?

I'm Pip. I know Saleh's experience, projects, writing, and how to work with him.

Answers are AI-generated and can be wrong.

Attachments

100%