open-next icon indicating copy to clipboard operation
open-next copied to clipboard

Cache control headers not set for static page with base path

Open qroll opened this issue 11 months ago • 1 comments

My organisation has two projects: one uses basePath in next.config.js and the other does not. I noticed that for the project using basePath, the default cache control header is not showing up for static pages. It shows up for the other project.

I narrowed the header setting down to this check here in fixCacheHeaderForHtmlPages (ref):

  if (
    HtmlPages.includes(localizedPath) &&
    !internalEvent.headers["x-middleware-prefetch"]
  ) {
    headers[CommonHeaders.CACHE_CONTROL] =
      "public, max-age=0, s-maxage=31536000, must-revalidate";
  }

If I patch the line to include the base path, then it works

HtmlPages.find((path) => `${NextConfig.basePath ?? ""}${path}` === localizedPath)

However, I'm not sure if this is the intended method or if there's a canonical way to treat base paths. If I could be pointed in the right direction, I'd be happy to submit a PR for this.

qroll avatar May 22 '25 10:05 qroll

Good catch @qroll!

You can open a PR with your suggested changes. I just tested this and the values in HtmlPages doesn't seem to have the basePath prefixed.

sommeeeer avatar May 23 '25 13:05 sommeeeer