Complete the code to disable caching for a Next.js Server Component.
export const revalidate = [1]; export default function Page() { return <h1>No caching here!</h1>; }
Setting revalidate = 0 tells Next.js not to cache the page and always fetch fresh data.
Complete the code to disable caching for a Next.js API route.
export const GET = async () => {
return new Response('No cache', {
headers: {
'Cache-Control': [1]
}
});
};Using 'no-store' in the Cache-Control header tells the browser and CDN not to cache the response.
Fix the error in disabling caching for a Next.js page by completing the export.
export const [1] = 0; export default function Page() { return <p>Fresh data always</p>; }
The correct export to control caching in Next.js pages is revalidate.
Fill both blanks to disable caching and set a custom header in a Next.js API route.
export const GET = async () => {
return new Response('No cache', {
headers: {
'Cache-Control': [1],
'Pragma': [2]
}
});
};Setting 'Cache-Control' to 'no-store' disables caching, and 'Pragma' to 'no-cache' is for backward compatibility with HTTP/1.0 caches.
Fill all three blanks to create a Next.js page that opts out of caching and fetches fresh data.
export const [1] = [2]; export default async function Page() { const res = await fetch('https://api.example.com/data', { cache: [3] }); const data = await res.json(); return <pre>{JSON.stringify(data, null, 2)}</pre>; }
Setting revalidate = 0 disables Next.js page caching. Passing { cache: 'no-store' } to fetch disables fetch caching, ensuring fresh data.