Performance: Sitemap.xml generation
MEDIUM IMPACT
This affects the initial page load speed and SEO crawling efficiency by providing search engines a clear map of site URLs.
import { NextResponse } from 'next/server'; export async function GET() { const urls = await getAllUrls(); const sitemap = `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls.map(url => `<url><loc>${url}</loc></url>`).join('')}\n</urlset>`; return new NextResponse(sitemap, { headers: { 'Content-Type': 'application/xml' } }); } // Server-side generation on request
export default function Sitemap() { const urls = getAllUrls(); return ( <xml> {urls.map(url => <url><loc>{url}</loc></url>)} </xml> ); } // This runs on client side and delays sitemap generation
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Client-side sitemap generation | N/A (client DOM heavy if rendered) | N/A | Blocks client rendering | [X] Bad |
| Server-side sitemap generation with streaming | N/A | N/A | No client paint impact | [OK] Good |