LaunchFast Logo LaunchFast

Integrated Dynamic Streaming-First Sitemap

Rishi Raj Jain
// ...
import { SitemapStream, streamToPromise } from 'sitemap'

export async function GET() {
  const hostname = ''
  const smStream = new SitemapStream({ hostname })
  const slugs = [/* static slugs */]
  try {
    slugs.forEach((url) => {
      smStream.write({ /* url config */ })
    // ...
    const sitemap = await streamToPromise(smStream)
    return webResponse(sitemap, 200, {
      'Content-Type': 'text/xml',
  } catch (e: any) {
    // handle errors
} comes with a sitemap.xml.ts Astro endpoint that creates a sitemap as a streaming response, making it available to crawlers such as Google as soon as they request the page. This was quickly done with the help of sitemap package on npm:

With Astro’s prerender configuration flag per page or endpoint, the sitemaps can also be pre-rendered and also later be statically re-generated using ISR.

Learn More Using PhotoSwipe in Astro to Build an Image Gallery → Using Transformers for Shiki to enrich Syntax Highlighting in Astro → Using GreenSock Animation Platform (GSAP) in Astro with View Transitions: A Step-by-Step Guide →