Performance: Creating pages
This affects the initial page load speed and how quickly the main content appears to the user.
--- export async function getStaticPaths() { const paths = await fetch('https://api.example.com/all-ids').then(res => res.json()); return paths.map(id => ({ params: { id } })); } const { params } = Astro; const data = await fetch('https://api.example.com/data/' + params.id).then(res => res.json()); --- <html> <body> <h1>{data.title}</h1> </body> </html>
---
// No static paths defined, prerender=false enables server rendering on each request
export const prerender = false;
const { params } = Astro;
const data = await fetch('https://api.example.com/data/' + params.id).then(res => res.json());
---
<html>
<body>
<h1>{data.title}</h1>
</body>
</html>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Server-side rendering on each request | Moderate (depends on data) | Multiple reflows due to delayed content | High paint cost due to late HTML arrival | [X] Bad |
| Static generation at build time | Minimal and fixed | Single reflow on initial paint | Low paint cost with instant HTML | [OK] Good |
.astro file inside the src/pages folder in an Astro project?src/pages. Each .astro file becomes a page.src/pages = new page URL [OK]/, which maps to index.astro in src/pages.src/pages and named index.astro to serve as homepage.index.astro inside src/pages. -> Option Dsrc/pages/index.astro [OK]index.astro in pages folder [OK]src/pages/about.astro with content:<!-- src/pages/about.astro --> <h1>About Us</h1> <p>Welcome to our site.</p>
about.astro inside src/pages maps to the URL path /about.src/pages from the URL, so the URL is /about.src/pages/contact.astro but visiting /contact shows a 404 error. What is the most likely cause?src/components instead of src/pages. Components folder files do not create routes.src/components instead of src/pages. -> Option B/blog/post1. Which file structure and naming is correct in Astro?src/pages create nested URL paths automatically.post1.astro inside src/pages/blog creates URL /blog/post1.src/pages/blog-post1.astro file creates flat URL /blog-post1. Create src/pages/blog/post1/index.html file creates no route (.html not supported as pages). Create src/pages/blog/post1.astro and add a routing config is incorrect because Astro does not require routing config.src/pages/blog/post1.astro file. -> Option APass the test and this pattern moves unknown