Correct way of prefetching data with NextJS App router
context: I am building a data entry app where the pages fetches the data based on the unique workspace name so say
/dashboard/workspaceName/theInternalPage
. I have noticed that when navigating btn diff pages takes longer time at first when the data is not yet fetched but once it is fetched navigating btn is instant and fast.
My question is, is it a good practice if i prefetch all of my queries in the middleware using queryClient.prefetchQuery
? this will fire the request a bit earlier as middleware is first executed in nextjs.
now on the /dashboard/workspaceName/InternalPage
I can still do the normal fetch but my guess is it will now look up at the cache and not wait for it to load. someone correct me on this one0 Replies