Skip to content
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

setting Cache-Control header in getServerSideProps on generated JSON is not working on production #10993

Closed
dulmandakh opened this issue Mar 12, 2020 · 2 comments · Fixed by #11022
Milestone

Comments

@dulmandakh
Copy link
Contributor

dulmandakh commented Mar 12, 2020

Bug report

Thank you for Next.js and it's 9.3 version, it's amazing.

Describe the bug

I'm trying to set reasonable Cache-Control header in getServerSideProps for generated JSON file, then it works on dev server but not on production builds or set to no-cache, no-store, must-revalidate.

But Cache-Control works as expected when you visit the link directly or for generated html.

I'm running my own server.

To Reproduce

  1. Create pages/about.js file with content like below
export async function getServerSideProps({ res }) {
  res.setHeader('Cache-Control', 'public, max-age=7200')
  return {
    props: {
    }
  };
}

export default function() {
  return <h1>About</h1>
}
  1. Create a like to about page using code below
<Link href="/about"><a href="/about">About</a></Link>
  1. Start dev server and open any page other than about, then navigate to about page. Then you will see about.json in a browser inspector and it's Cache-Control header set to public, max-age=7200.

  2. Build the project, and do the same as Step 3, but you'll see Cache-Control set to no-cache, no-store, must-revalidate

Expected behavior

I expect that Cache-Control header to be same as set in getServerSideProps either in dev or production build.

System information

  • OS: macOS
  • Browser: Chrome
  • Version of Next.js: 9.3.0

Additional context

I was able to reproduce the issue in a new next.js project.

@dulmandakh dulmandakh changed the title setting Cache-Control header in getServerSideProps on generated JSON is not working on production build setting Cache-Control header in getServerSideProps on generated JSON is not working on production Mar 12, 2020
@Timer Timer added this to the 9.3.1 milestone Mar 12, 2020
@dulmandakh
Copy link
Contributor Author

Thanks 🙏

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants