I'm building indexone.dev, where I've built a service that writes new job posts periodically. This service is independent from my web app, which means it can't automatically tell my web app to show new data. As a result, the application was serving cached or outdated data even though new data was available in the database.
On the other hand, I was fetching data on the server-side page, which does not revalidate data by default (this is to prevent unnecessary API calls).
Enter Revalidation: Keeping Your Data Fresh
Next.js provides two primary revalidation strategies:
- Time-Based Revalidation
- On-Demand Revalidation
you can learn more here.
In my case, Time-Based Revalidation made sense. To implement this, you just need to add one line at the top of your server-side page where you're fetching data.
and that's it. This whole problem took me hours to figure out, when the solution is just one line. I felt stupid.
Ask
If you learned something new about Next.js from this post, or it helped you solve a problem, consider trying out indexone.dev - where you can find some exciting Software Engineer jobs right after they're released, I'd love to get your feedback as it's still in the early stages and I've been building nonstop. Cheers🥂
Top comments (0)