Next.js 15: Optimizing Cache for Better Performance
Aman Suhag
The release of Next.js 15 brings significant updates to its caching strategy, offering developers greater control over caching behavior. These changes may require adjustments during the upgrade process, making it crucial to review the updated documentation.
Adapting to tool updates is a common aspect of frontend development. Let’s explore how these caching updates work and what adjustments you might need to make.
The Cache Strategy Changes
The caching changes affect three major types of requests:
Fetch requests: Default caching strategy is 'no-store'.
GET route handlers: Caching is disabled by default.
Client-side routing: Page components are no longer cached by default.
Let’s dive into the details.
Fetch Requests Default to no-store
In Next.js 14, fetch requests used the force-cache strategy by default:
In Next.js 15, fetch requests no longer cache data by default:
To enable caching explicitly:
For route segments, configure caching globally:
GET Route Handlers
Before (Next.js 14)
After (Next.js 15)
Add dynamic = 'force-static' to cache GET route responses.
Client-side Routing
In Next.js 14.2.0, the staleTimes experimental flag allowed custom caching configuration:
In Next.js 15, the default staleTime is 0, meaning data is fetched fresh during each navigation:
To enable caching:
Unchanged Behaviors
Shared layouts and loading.js remain cached.
Back/forward navigation still caches pages.
Conclusion
Next.js 15’s caching changes provide more control over caching behavior, enabling better SSR and SSG optimization. By understanding these updates and configuring caching effectively, you can ensure a smoother upgrade process while leveraging enhanced performance capabilities. Stay informed, adapt, and create high-performance applications!