Skip to content

Overwritten Cache-Control headers should include public directive #21827

@nrempel

Description

@nrempel

What version of Next.js are you using?

10.0.7-canary.3

What version of Node.js are you using?

15.7.0

What browser are you using?

Chrome, Safari, curl

What operating system are you using?

macOS

How are you deploying your application?

next build, next start

Describe the Bug

Cache-Control headers are overwritten to be: Cache-Control: s-maxage=31536000, stale-while-revalidate. This header should include the public directive so that CDNs will cache the response.

As an aside, headers are not overwritten consistently. If I have the following config:

// next.config.js

module.exports = {
  async headers() {
    const headers = [
      {
        headers: [
          {
            key: "Cache-Control",
            value:
              "public, max-age=3600, s-maxage=60, stale-while-revalidate=86400",
          },
        ],
        source: "/:path*",
      },
    ];
    return headers;
  },
};

Making a request to / will return the header: Cache-Control: s-maxage=31536000, stale-while-revalidate but making a request to /posts/first-post returns the header Cache-Control: public, max-age=3600, s-maxage=60, stale-while-revalidate=86400.

Expected Behavior

The headers should be overwritten consistently across all pages. The overwritten headers should include the public directive.

To Reproduce

  1. Clone https://github.com/nrempel/repro-cache-control-headers
  2. npm build && npm start
  3. Visit / and look at headers
  4. Visit /posts/first-post and look at headers

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.lockedstaleThe issue has not seen recent activity.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions