Hey coding fam! Next.js 15 just rolled up with some crazy changes, and I’m here to spill the tea on the Caching glow-up compared to version 14. Stuff that used to auto-cache like it’s no big deal? Yeah, that’s out the window now. Ready to vibe with this? Let’s jump in! 🔥
What’s the Deal with This Change? 🤔
Caching in Next.js 15 is all about handing you the keys. Back in 14, everything cached by default, like your phone hoarding every pic you snap. Fast? Yup. But sometimes it’d throw old vibes your way when you needed fresh ones. Now 15’s like, “You pick what stays!” It’s quicker, cleaner, and way less glitchy. 😏
What’s Running Without Cache Now? 🔍
Here’s the crew that’s dropped the auto-cache habit:
-
fetch
requests: No more stashing by default, every grab’s a new haul unless you lock it in. -
Route Handlers
with GET: These guys won’t save anything unless you give the green light. -
Client-side navigation: Hopping pages with
<Link>
? Fresh data every time, no stale crumbs!
Show Me How It Works! 💻
Imagine a page snagging a product list. Back in Next.js 14, it was like:
// app/products/page.js
async function getProducts() {
const res = await fetch('https://api.example.com/products');
return res.json();
}
export default async function ProductsPage() {
const products = await getProducts();
return (
<ul>
{products.map((product) => (
<li key={product.id}>{product.name}</li>
))}
</ul>
);
}
Instant cache vibes! But in Next.js 15, it’s a fresh pull every time unless you tweak it. Wanna keep it cached? Add this:
// app/products/page.js
async function getProducts() {
const res = await fetch('https://api.example.com/products', { cache: 'force-cache' });
return res.json();
}
export default async function ProductsPage() {
const products = await getProducts();
return (
<ul>
{products.map((product) => (
<li key={product.id}>{product.name}</li>
))}
</ul>
);
}
It’s like telling Next.js, “Keep this on lock, fam!” Or for a Route Handler:
// app/api/data/route.js
export const dynamic = 'force-static';
export async function GET() {
const data = await fetchSomeData();
return NextResponse.json({ data });
}
Why’s This a Big Win? 🌟
If your site’s stuck on auto-cache, it’s like gaming with a laggy headset, works, but kinda whack! 😂 This new flow keeps your data fresh and lets you run the show. Coming from 14? You’ll need to sprinkle some cache magic yourself, but that speed boost is clutch. Too chill to tweak? Test it out, it’s a total vibe! 😜
Sneaky Extra Trick! 🎉
Next.js 15 is all about that “your rules” energy. Wanna cache client-side navigation? Mess with staleTimes
in next.config.js
like this:
const nextConfig = {
experimental: {
staleTimes: {
dynamic: 30, // 30-second cache
static: 180, // 3-minute cache
},
},
};
module.exports = nextConfig;
Next.js 15 isn’t in your face about it, just chilling ‘til you say what’s up. Go test it out now and slay it like a coding beast! 💪
Thanks for reading! 🙏🏻 Hope this was a vibe ✅ React and follow for more 😍 Made with 💙 by Mahdi Jazini |
![]() ![]() |
---|
I just read the article about Next.js 15, and I have to say, the part where it explains how developers can now decide which data to cache and which not to is super practical. It’s amazing how much control this gives us, making our apps more efficient and tailored to our needs. I definitely learned something new today, and I really appreciate how clearly it was explained. Thanks so much for sharing this—it’s got me excited to experiment with these features. I’m already thinking about how this will improve my next project!😍