Opting Out of Caching in Next.js
📖 Scenario: You are building a Next.js app that shows the current time on a page. You want to make sure the page always shows the latest time and does not use any cached version.
🎯 Goal: Create a Next.js server component page that displays the current time and opts out of caching so it updates on every request.
📋 What You'll Learn
Create a server component page file named
page.tsxUse the
revalidate = 0 cache option to disable cachingDisplay the current time using
new Date().toLocaleTimeString()Export a default async function named
Page that returns the JSX💡 Why This Matters
🌍 Real World
Web apps often need to show live or frequently changing data, like stock prices or current time, where caching must be disabled to keep data fresh.
💼 Career
Understanding how to control caching in Next.js is important for building performant and accurate web applications that meet user expectations.
Progress0 / 4 steps