“Zero JavaScript by default” means an Astro page ships no client-side JavaScript unless you ask for it. Astro components run on the server or at build time and turn into plain HTML and CSS; the browser only receives JavaScript for components you mark with a client:* directive, <script> tags you write, and a few opt-in features such as the client router. It’s a default, not a ban: you choose where JavaScript goes, one component at a time.
That’s different from most JavaScript frameworks, where the whole page is a client application and the framework runtime always loads. This explainer covers what Astro zero JavaScript actually covers, which features add scripts back, and how to check what your own build sends.
Key Takeaways
.astrocomponents never send their code to the browser; their frontmatter runs on the server or at build time and outputs HTML.- Framework components (React, Vue, Svelte, Solid, Preact) render to static HTML unless you add a
client:*directive.- JavaScript comes back through islands,
<script>tags,<ClientRouter />, prefetch and server islands, each one opt-in.- Check
dist/afterastro build: a page with no islands or scripts has no<script>tags.- Less JavaScript usually means faster loading and better INP, but images, fonts and third-party tags still matter.
What zero JavaScript by default covers
An Astro component has two parts: a frontmatter script between the --- fences, and a template. The frontmatter is where you fetch data, read props and import other components. All of it runs on the server, either once at build time for static pages or per request for on-demand pages.
---
// src/components/LatestPosts.astro
import { getCollection } from 'astro:content';
const posts = (await getCollection('blog'))
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf())
.slice(0, 3);
---
<ul>
{posts.map((post) => (
<li><a href={`/blog/${post.id}/`}>{post.data.title}</a></li>
))}
</ul>
The browser receives only the resulting <ul>. The collection query, the sort, and the getCollection import never leave the server. There’s no hydration step for this component and no framework runtime to download, because there’s nothing left to run.
This also applies to UI framework components. Import a React component into an Astro page without a directive and Astro calls the React renderer on the server, outputs its HTML, and stops there:
---
// src/pages/index.astro
import PricingTable from '../components/PricingTable.jsx';
---
<!-- Rendered to HTML on the server. No React is sent to the browser. -->
<PricingTable plans={['Starter', 'Pro']} />
If PricingTable only displays data, that’s exactly what you want. If it has a toggle that should work in the browser, it needs a directive.
Where JavaScript comes back
Every way JavaScript reaches the browser in Astro is something you add on purpose. Here are the common ones:
| Feature | What ships | How you opt in |
|---|---|---|
| Island | The component’s code, its framework runtime, and its props | client:load, client:idle, client:visible, client:media, client:only |
<script> tag |
Your script, bundled and loaded as a module | Writing a <script> in a component |
is:inline script |
Your script exactly as written, inline in the HTML | <script is:inline> |
| Client router | Astro’s router for view transitions | <ClientRouter /> in the layout |
| Prefetch | A small script that preloads linked pages | prefetch: true in astro.config.mjs |
| Server islands | A small inline script that fetches the deferred HTML | server:defer on a component |
| Integrations | Whatever the integration injects | Installing it (for example Partytown, analytics) |
The dev toolbar also injects scripts, but only during astro dev. It never appears in a production build.
Islands
A directive turns a component into an island: Astro renders it to HTML on the server, then loads its JavaScript in the browser and hydrates it. The directive controls when:
---
// src/pages/product.astro
import AddToCart from '../components/AddToCart.jsx';
import Reviews from '../components/Reviews.jsx';
---
<AddToCart client:load productId="mug-01" />
<Reviews client:visible productId="mug-01" />
client:load hydrates as soon as the page loads, and client:visible waits until the component scrolls into view. Only these two components ship code. The rest of the page stays HTML. The client directives explainer covers all five directives, and hydration in Astro shows what happens in the browser.
Script tags
For small behaviour you often don’t need a framework at all. A <script> in an Astro component is processed by Astro: TypeScript is compiled, imports are bundled, and the result loads as a module. It’s included once per page even if the component appears many times.
---
// src/components/CopyButton.astro
---
<button type="button" data-copy="npm create astro@latest">Copy</button>
<script>
document.querySelectorAll<HTMLButtonElement>('[data-copy]').forEach((button) => {
button.addEventListener('click', () => {
navigator.clipboard.writeText(button.dataset.copy ?? '');
button.textContent = 'Copied';
});
});
</script>
This adds a few lines of JavaScript instead of a framework runtime. The island or script guide helps decide which one a component needs.
Why Astro defaults to zero JavaScript
Most marketing sites, blogs, docs and portfolios are content. The reader needs text, images and links, and maybe a menu toggle and a form. Shipping a full client application to render a blog post means the browser downloads, parses and runs code that only reproduces HTML the server could have sent directly.
Astro’s design flips the default. Instead of starting interactive and removing JavaScript where possible, it starts static and adds JavaScript where needed. This model is usually called islands architecture: a static page with small, independent interactive regions. The islands architecture guide covers the idea in depth.
The practical effects:
- Faster first load. The page is readable as soon as the HTML and CSS arrive. There’s no wait for a bundle to execute before content appears.
- Less main-thread work. Less JavaScript means less parsing and execution, which helps Interaction to Next Paint (INP) on slower phones.
- Fewer things to break. A page with no client code can’t fail because a script errored or a third-party bundle changed.
- Works without JavaScript. Links, content and plain forms still work if scripts are blocked or fail to load.
None of this guarantees a fast site. A 4 MB hero image, a blocking web font or a heavy third-party tag will still hurt Largest Contentful Paint. Zero JavaScript by default removes one common cause of slow pages, not all of them.
Zero JavaScript vs other frameworks
Other frameworks have moved toward sending less JavaScript too, with different approaches:
| Approach | Example | What the browser gets by default |
|---|---|---|
| Static HTML with islands | Astro | HTML and CSS; JS only for opted-in components |
| Full hydration | Classic React SPA, Gatsby | Framework runtime plus code for the whole page |
| Server Components | Next.js App Router | HTML, plus the React runtime and client component code |
| Resumability | Qwik | HTML plus a small loader; code fetched on interaction |
The key difference with Astro is that “no JavaScript” is the starting state for every component, and there’s no framework runtime unless an island needs one. The Astro islands vs React Server Components comparison goes through the trade-offs.
How to check what your Astro site ships
You don’t have to take the default on trust. Build the site and look at the output:
# Build, then list the JavaScript Astro emitted
npm run build
find dist -name "*.js" | head
# Find pages that include any script tag
grep -rl "<script" dist --include="*.html"
Hashed client bundles land in dist/_astro/. If a page has no islands, scripts or opt-in features, its HTML has no <script> tags at all. If you see a script you don’t expect, search your layouts for client: directives, <script> tags and <ClientRouter />, and check what your integrations inject.
In the browser, open DevTools, go to the Network panel, filter by JS and reload. That shows exactly what one page downloads. For bundle sizes over the whole build, the bundle size analysis tip uses a Vite visualizer plugin.
Common sources of unexpected JavaScript
- A
client:loadadded to a component in the base layout, which loads on every page. - A framework component used for a static header or footer with a directive it doesn’t need.
<ClientRouter />or prefetch enabled site-wide when only a few pages benefit.- Analytics, chat widgets, embeds and cookie banners added as third-party scripts.
Keeping a site at zero JavaScript
Treat client JavaScript as a budget. Before adding a directive, ask whether the component needs to run in the browser at all, and if so, when. Many common UI patterns work with HTML and CSS alone: <details> for accordions, <dialog> for modals with a few lines of script, CSS scroll snap for carousels, and plain forms that post to an endpoint.
When you do need an island, pick the latest directive that still works, usually client:visible or client:idle, and keep the island small. Pass it the data it needs as props rather than wrapping a large section of the page in one component. The Astro performance guide covers the rest of the speed checklist.
Komal themes follow this default: pages are static Astro components, and interactive parts are added only where a component needs them. If you’d like to see the pattern in a finished project, you can browse Astro themes and inspect any live preview in DevTools. The official Astro islands documentation is the reference for the model.
FAQ
Does Astro really ship zero JavaScript?
By default, yes. A page built only from .astro components and framework components without directives contains no client-side JavaScript. JavaScript is added when you use a client:* directive, a <script> tag, <ClientRouter />, prefetch, server islands or an integration that injects scripts.
Can I use React in Astro without shipping JavaScript?
Yes. A React component used without a client:* directive is rendered to HTML on the server and no React code reaches the browser. It won’t respond to clicks or state changes, so this works for components that only display content.
Does zero JavaScript mean Astro can’t build interactive sites?
No. You add interactivity per component with client directives or <script> tags, and you can use React, Vue, Svelte, Solid or Preact for those islands. The rest of the page stays static, so interactive parts don’t force JavaScript onto the whole site.
Does Astro’s frontmatter code run in the browser?
No. Code between the --- fences runs on the server, at build time for prerendered pages or per request for on-demand pages. It can use secrets, databases and file system access because none of it is sent to the client.
Is zero JavaScript good for SEO?
It helps. Search engines and AI crawlers receive complete HTML without needing to execute scripts, and less JavaScript usually improves Core Web Vitals such as INP. Rankings still depend on content, links and technical SEO, so it’s one advantage among several.