Next.js Discord

Discord Forum

how to prevent pages from being cached in next js

Unanswered
Giant panda posted this in #help-forum
Open in Discord
Giant pandaOP
wanted to prevent my back/forward pages from being cached in next js i am using client components , i have tried the options mentioned in the docs such adding these variables to my page.js , layout.js files
export const fetchCache = "force-no-store";
export const dynamic = 'force-dynamic'
export const revalidate = false;

adding a meta tag
 <meta name="cache-control" content="no-cache, no-store, must-revalidate" />

, i adjusted the next.config to
/** @type {import('next').NextConfig} */
const nextConfig = {
  async headers() {
    return [
      {
        source: '/(.*)',
        headers: [
          {
            key: 'Cache-Control',
            value: 'no-store, no-cache, must-revalidate, proxy-revalidate',
          },
        ],
      },
    ];
  },
};
export default nextConfig;

as well but all of these solutions didn't work

5 Replies

Trigg Hound
in the page.tsx(jsx) have you tried

export const dynamic = "force-dynamic"
Giant pandaOP
i have tried
export const fetchCache = "force-no-store";
export const dynamic = 'force-dynamic'
export const revalidate = false;
, adding a meta tag with cache control set to no-cache to my root layout as well didn't work
btw i am using a client component
Citrus blackfly parasitoid
Are you at next@latest or @canary with dynamic iO enabled?
Giant pandaOP
i am using next js 14.2