Astro is designed to send as little JavaScript as possible to the browser. What is the main reason for this design choice?
Think about how sending less code to the browser affects user experience.
Astro ships zero JavaScript by default to improve performance. Sending less JavaScript means faster page loads and less work for the browser, making websites feel quicker and more responsive.
By default, Astro ships zero JavaScript. What changes when you add a component with client-side interactivity?
Think about how Astro balances zero JavaScript by default with interactive features.
Astro ships zero JavaScript by default but will include JavaScript only for components that need it. This keeps the page fast while enabling interactivity where required.
Astro uses special directives to control when JavaScript is sent to the browser. Which directive tells Astro to load JavaScript only when the component is visible on screen?
Consider which directive delays loading until the user can actually see the component.
The client:visible directive loads JavaScript only when the component scrolls into view, improving performance by delaying unnecessary code.
You created an Astro page with only static HTML and CSS, but the browser network tab shows JavaScript files being loaded. What is a likely cause?
<pre>--- import SomeComponent from '../components/SomeComponent.jsx'; --- <html> <body> <SomeComponent /> </body> </html></pre>
Check what the imported component might be doing behind the scenes.
If you import a component that includes client-side JavaScript, Astro will send that JavaScript even if you don't explicitly mark it as interactive. This causes JavaScript files to load.
Consider this Astro component code:
---
let count = 0;
function increment() {
count++;
}
---
Count: {count}
What will the user see and what JavaScript is sent to the browser?
Think about how Astro handles interactivity and state without client directives.
Astro ships zero JavaScript by default, so event handlers like on:click in this code do not work unless you add a client directive. The count will not update on click.
