Next.js Discord

Discord Forum

Prod users getting 404 on chunks

Unanswered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
Hello,
We're facing an issue, which we could not find a solution for yet.

It looks like some of our users are being served an outdated build of our app.
Early last week, following disruptions encountered by a service we are using, we cleared Vercel cache.
Some of our users starting encountering errors when loading some pages in the app.
Reviewing these errors, a common pattern is that they are requesting chunks that do not exist anymore.

We realised that these were being served old versions of our app and therefore started investigating default caching config in Next14.
The defaults being pretty agressive we subsequently changed the browser headers to the following in next.config:
async headers() {
    return [
      {
        source: '/:path*',
        headers: [
          {
            key: 'X-Frame-Options',
            value: 'SAMEORIGIN'
          },
          {
            key: 'X-Content-Type-Options',
            value: 'nosniff'
          },
          {
            key: 'Referrer-Policy',
            value: 'strict-origin-when-cross-origin'
          },
          {
            key: 'Permissions-Policy',
            value:
              'camera=(), microphone=(), geolocation=(), interest-cohort=()'
          },
          // Disable browser caching for all routes to force full reloads
          {
            key: 'Cache-Control',
            value: 'no-cache, no-store, must-revalidate, max-age=0'
          },
          {
            key: 'Pragma',
            value: 'no-cache'
          },
          {
            key: 'Expires',
            value: '0'
          }
        ]
      }
    ]
  },


We just had a client in a meeting. Despite the above settings he was still being served the old version of the app.
We had him check the 'disable cache' checkbox in his devtools and it immediately worked.

How can we enforce the build being refreshed for all of our users?
We are using Vercel and Next 14.2.8.

4 Replies

Giant pandaOP
Bumping 🙂
@Giant panda Bumping 🙂
Unfortunately I don't believe you can, this is a web browser issue (I believe)
Browsers cache information to improve efficiency and loading times, a site itself would need to.change addresses for all cache to reset.
Giant pandaOP
@Natxeula Thank you for your reply. We ended up activating skew protection on top of the above and the issue went away.
I don't know the specifics governing this in Next, and we did not get to the bottom of what exactly triggered it (cache deletion or deps change), but at least our users are being served the correct version.