Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
qroll opened this issue May 22, 2025 · 1 comment · May be fixed by #880
Open

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

qroll opened this issue May 22, 2025 · 1 comment · May be fixed by #880

Comments

@qroll
Copy link

qroll commented May 22, 2025

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.

@sommeeeer
Copy link
Contributor

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.

@conico974 conico974 linked a pull request May 25, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants