Next.js Discord

Discord Forum

Sitemap not caching

Unanswered
Chippiparai posted this in #help-forum
Open in Discord
ChippiparaiOP
Using Next 14.1.0, I've created a dynamic sitemap using a sitemap.ts file in the app directory, however no matter what I try the Cache-Control Header comes through as public, max-age=0, must-revalidate.

How can I get the same cache functionality used on pages? i.e. Cache-Control = s-maxage=31536000, stale-while-revalidate and use tags on fetches for on-demand revalidation?

Here is the extremely stripped down code I tried, no fetches, only 2 hard-coded sitemap entries:

import { MetadataRoute } from "next";

export const revalidate = 3600;

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  return [
    {
      url: "https://www.example.com",
      lastModified: "1970-01-01T00:02:03.123Z",
      changeFrequency: "monthly",
      priority: 1,
    },
    {
      url: "https://www.example.com/resources",
      lastModified: "1970-01-01T00:02:03.123Z",
      changeFrequency: "monthly",
      priority: 0.8,
    },
  ];
}

1 Reply

ChippiparaiOP
If a tree falls on a mime in the middle of a forest, does it make a sound, or does it play one from the cache?