Performance: 404 and error pages
This affects the page load speed and user experience when users hit a missing or error page.
export function GET() {
return new Response('<h1>404 - Page Not Found</h1><p>Sorry, this page does not exist.</p>', {
status: 404,
headers: {'content-type': 'text/html'}
});
}export async function GET({ params }) { // Heavy data fetching or complex logic const data = await fetch('https://api.example.com/data'); if (!data.ok) { return new Response('Page not found', { status: 404 }); } return data; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy data fetching in 404 page | Multiple nodes due to dynamic content | Triggers 1 reflow after data loads | Higher paint cost due to complex layout | [X] Bad |
| Static simple 404 page | Few nodes with simple markup | Single reflow on initial paint | Low paint cost with minimal styles | [OK] Good |
404.astro page in an Astro project?404.astro is used to show a friendly message for missing pages.404.astro to detect and serve 404 error pages automatically.404.astro matches the required name; others won't be recognized automatically.404.astro code snippet, what will the user see when visiting a missing page?<!-- 404.astro --> <h1>Oops! Page not found.</h1> <p>Try going back to the <a href='/'>homepage</a>.</p>
404.astro page but it does not show when visiting a missing page. What is the most likely mistake?404.astro to be in the root of the src/pages folder, not inside components.src/components, Astro won't serve it automatically as a 404 page.404.astro file is inside the src/components folder -> Option A404.astro and 500.astro to handle different error codes automatically.404.astro and 500.astro files in src/pages -> Option APass the test and this pattern moves unknown