Server Side Fetching vs Client side swr - Performance
Answered
Riday 💙 posted this in #help-forum
Riday 💙OP
Which is better performance wise?
I am making a table which will have pagination, sorting, and search. Considering this, is it better to fetch the data in a server component directly from the db or in a client component using something like swr and api route?
I am making a table which will have pagination, sorting, and search. Considering this, is it better to fetch the data in a server component directly from the db or in a client component using something like swr and api route?
Answered by B33fb0n3
using SSR is better from the performance perspective. For the DX it should be a little easier to pull all data via the client. If I would be in your situation I would fetch the first table entries serverside and if the user clicks for example on next page fetch the next site clientside
5 Replies
@Riday 💙 Which is better performance wise?
I am making a table which will have pagination, sorting, and search. Considering this, is it better to fetch the data in a server component directly from the db or in a client component using something like swr and api route?
using SSR is better from the performance perspective. For the DX it should be a little easier to pull all data via the client. If I would be in your situation I would fetch the first table entries serverside and if the user clicks for example on next page fetch the next site clientside
Answer
@B33fb0n3 using SSR is better from the performance perspective. For the DX it should be a little easier to pull *all* data via the client. If I would be in your situation I would fetch the first table entries serverside and if the user clicks for example on *next page* fetch the next site clientside
Riday 💙OP
I guess I can just implement all the filtering and pagination stuff using search params with server components too and I am not really worried about DX.
The code is pretty much similar
@Riday 💙 I guess I can just implement all the filtering and pagination stuff using search params with server components too and I am not really worried about DX.
Yea, that's also a possible thing. To give you the answer to wether serverside fetching or clientside fetching, you should fetch on server