[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live) [Discussions](/c/community/4) # Next.js Performance Question: Optimizing Data Loading Strategy 👇 60 views · 3 likes · 2 posts Icedog23 (@icedog23) · 2024-10-29 · ♥ 1 Next.js Performance Question: Optimizing Data Loading Strategy 👇 I'm working on a Next.js app and need advice on the best approach for handling data loading in the following scenario: 📈 Current Flow 1. User creates an event (data saved to DB) 2. Response data is stored in the Recoil state 3. The user is redirected to the event detail page 🔴 The Challenge I have two distinct ways users access the event detail page: 🧭 Internal Navigation - User comes from event creation - Event data already exists in the Recoil state - Should use this data for instant display 🔗 External Access - User comes from social media links - Need to fetch data using URL ID - Should be server-side rendered for SEO and performance 🔴 The Problem Using a server component would be ideal for SEO and performance, but it forces an API call on every page load - even when we already have the data in the state. 🔎 What I'm Looking For A solution that: - Uses existing state data when available - Only calls the API when necessary - Maintains good SEO - Optimizes performance Has anyone solved a similar use case? What's the recommended pattern for this in Next.js? Eric Burel (@eric-burel) · 2024-10-30 · ♥ 2 I am not sure about your exact setup but generally server-side prerendering should be thought as a way to populate your state So you'd want to store relevant state in the database for scenarios where users does a hard refresh/navigation, and then pass it to Recoil to warn your local state Not sure but maybe what you miss here is a background sync between Recoil and your db? Like on every recoil state change, you asynchronously save relevant items in your db, so if user's hit refresh you are able to reconstruct a proper state