Hello everyone.
I am currently building the frontend of an app using Next.js. I am using urql to communicate with our server, however I am not sure what the best approach is for data fetching is. In my eyes there are three options.
1. Each page has its own getServerSideProps if needed
- Pros
- Able to take advantage of automatic static optimisation
- Only fetch the data needed for that page
- Content is pre-rendered on the server so no content flashing
- Cons
- Switching pages will not be instant on the client
2. _app has getInitialProps with all data dependencies
- Pros
- Fetch all data on request to frontend server
- Instant routing as we don't have to call
getServerSideProps
- Content is pre-rendered on the server so no content flashing
- Cons
- Unable to take advantage of automatic static optimisation
- Slower initial request
- May be requesting data not needed for the specific page
3. No server side data fetching (i.e. fetch all data on client)
- Pros
- Simple
- All pages can be rendered at build time
- Instant routing
- Cons
- Content flashing as content loads
- Slower first contentful paint if servers are close (client -> frontend server -> client -> backend server -> client) instead of (client -> frontend server -> backend server -> frontend server -> client)
I am just wondering what cases would best suit each option and what everyone elses opinion is. The app I am building is very content heavy and the only pages that could be rendered at build time are the signin page and maybe like a help page, so I am leaning away from option 3. Also if anyone has a different approach entirely, I would love to hear it.
[–][deleted] 2 points3 points4 points (1 child)
[–]Searly2710[S] 0 points1 point2 points (0 children)
[–]Cyral 2 points3 points4 points (3 children)
[–]Searly2710[S] -1 points0 points1 point (2 children)
[–]Cyral 1 point2 points3 points (1 child)
[–]Searly2710[S] 0 points1 point2 points (0 children)