I'm trying to conditionally SSR a Next page and the lack of answers on the internet with a similar scenario as me lead me to believe my understanding of NextJS and SSR altogether is slightly incorrect, so I would love some clarification.
Here is my understanding: having the function getServerSideProps
exported in our page file tells Next that we want to SSR said page and pass server-fetched data to our page. Therefore, if I want to conditionally SSR this page, I need to only call getServerSideProps
sometimes. After some research, I thought that using the Dynamic Import from next/dynamic
would solve this problem, as you're able to conditionally apply SSR, however, it appears that even when I wrap my page component in the dynamic
function (as specified Here), getServerSideProps
is still being called.
Here is my desired functionality: I want to only SSR a page if my client cache does not already contain the data required by that page. In other words, I want to first check if the client cache contains the data required by the page, and if it does, use the data to render that page, and if it does not, I would then like to perform SSR and get said data in getServerSideProps
.
Is this even possible? Or is my understanding of the framework incorrect?
Any clarification or advice would be greatly appreciated!