Introduction
Astro sends no JavaScript to the browser unless you ask for it. This makes websites faster and simpler because less code runs on your visitor's device.
Astro sends no JavaScript to the browser unless you ask for it. This makes websites faster and simpler because less code runs on your visitor's device.
No special syntax is needed to ship zero JavaScript. Just write your Astro components normally without adding client-side scripts.--- // No client directives here --- <h1>Hello, world!</h1>
client:load, which tells Astro to send the Counter script to the browser.--- import Counter from './Counter.jsx'; --- <Counter client:load />
This simple Astro page renders static HTML with no JavaScript sent to the browser. It loads very fast and works everywhere.
--- // src/pages/index.astro --- <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Astro Zero JS Example</title> </head> <body> <h1>Welcome to Astro!</h1> <p>This page ships zero JavaScript by default.</p> </body> </html>
Astro's default behavior helps improve website speed and reduces data usage.
You can add JavaScript only where needed, keeping the rest of your site lightweight.
Astro sends no JavaScript to the browser unless you explicitly add it.
This approach makes sites faster and simpler.
You add JavaScript only with special client directives.
client:load to add JavaScript loading behavior.<MyComponent client:load /> uses the correct client:load syntax.<MyWidget client:idle />
client:idle directive loads JavaScript when the browser is idle.<MyButton client:load>Click</MyButton>
client:load requires the component to have JavaScript to load.MyButton has no JavaScript, the directive does nothing.client:load only to the button loads JS just where needed.Pass the test and this pattern moves unknown