Sometimes you want your web page to always show fresh data. Opting out of caching helps you do that by telling Next.js not to save the page content for later.
When showing live data like stock prices or sports scores that change often.
When displaying user-specific information that should not be shared or stored.
When debugging and you want to see changes immediately without cached versions.
When your page content depends on real-time events or external APIs that update frequently.
Syntax
NextJS
exportconst revalidate = 0;
Setting revalidate to 0 tells Next.js to never cache the page.
This is used in server components or page files to control caching behavior.
Examples
This page will never be cached and always fetch fresh data on every request.
The variable revalidate must be exported to affect caching.
Step 2: Identify missing export
Without export, Next.js ignores the variable and uses default caching.
Final Answer:
Missing export keyword for revalidate -> Option A
Quick Check:
revalidate must be exported to disable caching [OK]
Hint: Always export revalidate to control caching [OK]
Common Mistakes:
Forgetting to export revalidate
Thinking revalidate must be non-zero
Confusing functional and class components
5. You want a Next.js page to always show fresh data but only disable caching for authenticated users. Which approach correctly opts out of caching only for them?
hard
A. Set revalidate = 0 inside getStaticProps conditionally
B. Set export const revalidate = 0; unconditionally in the page file
C. Use server-side rendering with export const dynamic = 'force-dynamic'; and check auth inside
D. Add Cache-Control: no-store header in _app.js for all requests
Solution
Step 1: Understand conditional caching needs
Disabling caching only for authenticated users requires dynamic rendering based on request context.
Set export const revalidate = 0; unconditionally in the page file disables caching for all users; Set revalidate = 0 inside getStaticProps conditionally is invalid because revalidate is static; Add Cache-Control: no-store header in _app.js for all requests affects all requests globally.
Final Answer:
Use server-side rendering with export const dynamic = 'force-dynamic'; and check auth inside -> Option C