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

/manifest.webmanifest not cached by browser and reloaded on every page transition #64864

Open
cbratschi opened this issue Apr 22, 2024 · 3 comments
Labels
bug Issue was opened via the bug report template. Metadata Related to Next.js' Metadata API.

Comments

@cbratschi
Copy link

Link to the code that reproduces this issue

https://github.com/cbratschi/nextjs-issues/tree/manifest

To Reproduce

  1. npm run dev
  2. navigate between pages
  3. manifest.webmanifest is loaded on every page

Current vs. Expected behavior

Ideally a hash would be added to the manifest URL (current first):

<link rel="manifest" href="/manifest.webmanifest">
<link rel="manifest" href="/manifest.webmanifest?hash">

This allows using immutable versions of the manifest.

In addition the cache-control value should be modified (current first):

public, max-age=0, must-revalidate
public, max-age=31536000, immutable

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:37 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6031
  Available memory (MB): 65536
  Available CPU cores: 16
Binaries:
  Node: 20.11.1
  npm: 10.2.4
  Yarn: 1.22.21
  pnpm: N/A
Relevant Packages:
  next: 14.2.2 // Latest available version is detected (14.2.2).
  eslint-config-next: 14.2.2
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Metadata

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)

Additional context

I tried to set cache-control in next.config.js to get at least a max-age of one hour but ended with two cache-control headers being returned:

    async headers() {
        return [{
            //cache the manifest file (default: public, max-age=0, must-revalidate)
            //FIXME output contains now two header (ours is the first one)
            headers: [{
                key: 'cache-control',
                value: 'public, max-age=3600'
            }],

            source: '/manifest.webmanifest'
        }];
@cbratschi cbratschi added the bug Issue was opened via the bug report template. label Apr 22, 2024
@github-actions github-actions bot added the Metadata Related to Next.js' Metadata API. label Apr 22, 2024
@mkxml
Copy link

mkxml commented May 28, 2024

Yeah, I can reproduce this exact problem. Is there any workaround for this?

@janpaepke
Copy link

janpaepke commented Jun 6, 2024

I ran into this as well. Similar to @cbratschi I tried forcing it via middleware:

if (pathname.startsWith('/manifest')) {
	const response = NextResponse.next();
	response.headers.set('Cache-Control', `public, max-age=315360000, immutable`);
	return response;
}

This also resulted in duplicated cache control headers:
image

@joriregter
Copy link

Also having this issue. This does not solely apply to manifest routes, all metadata routes are affected. Sitemap and robots display the same bugs.

ijjk added a commit that referenced this issue Sep 23, 2024
…fied by user (#70127)

Fixes #70086 and #64864 (partially)

### What?
When user wants to override for certain headers such as `content-type`
or `cache-control` via `next.config` file or through middleware, nextjs
sends multiple header values by combining the user's headers with its
own default values for such headers. An example is demonstrated here:


https://github.com/user-attachments/assets/7b38331b-9137-485d-9285-d0b0d0e1e5ac


### Why?
Duplicate header values are a problem.

### How?
Maintaining a list of headers which cannot have duplicate values, and
then checking if the user has overridden any of those headers. If so,
user overrides are respected and sent over.

Demonstration of the correct behaviour after this fix:

Using `next.config` file:


https://github.com/user-attachments/assets/65e2aafb-dffc-47f4-bfcf-cf26a66865db



Using `middleware`:


https://github.com/user-attachments/assets/67636145-10eb-4504-ad78-800c1307c550

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Metadata Related to Next.js' Metadata API.
Projects
None yet
Development

No branches or pull requests

4 participants