Skip to content

Cache control headers not set for static page with base path #872

Open
@qroll

Description

@qroll

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions