reactjsnext.jsserver-side-renderingjamstack

How to fetch changed data in pre-rendered static generated page in nextjs


If I use nextjs pre render static generation page then what about the future changed data ? Suppose I use a ecommerce product details page or assume I use this static generation for a blog posts. If tomorrow the product price will be changed or the blog posts will be edited then how to get this updated data. Should I build the project in the server again ?

Surfing the nextjs documentation I found there are some types of rendering available -

  1. Pre-rendering Static generation
    1. Static generation without external data
    2. Static generation with external data. Here some external api is used in build time for fetching data
  2. Server Side rendering.

In my above question I talked about the way mentioned in point number 1.2 and I asked that if the data will be changed after build then how to fetch it.

Is it possible at all to get updated data without re-build the app in server ?

I am fear to use the point 2 because it may be slower. I think my current pure react app is faster than this way.


Solution

  • If your application has constantly changing / dynamic data, I'd recommended you use CSR (Client side rendering). Look into useSWR.

    For your use case, if you really want to leverage the power of Next.js you can choose to SSG (Pre-render) your product list pages and then CSR or SSR your product detail pages.

    Incremental builds in the future should fix this.