Tuesday 13 June 2017

Server Side rendering or Client side ? What to do when your server side needs to send a lot of data to a particular end point

So say I have a url end point of /game, in game I have a lot of information that is coming from the database...so do I just pass everything to the render function after I query from the database ? I am talking like 10 different objects here. This is going to be big ! How exactly should this be handled ? Here is a very simple example...app.get('/game', (res, req) => { queryDatabaseHere().then((data)=>{ querySomeMoreData.then((moredata) => { res.render('game.ejs', {a:353}, {data:data}, {b:2354}, {moredata: data}, .... etc. etc. more data would be passed here.) }) }) }) Oh but I'm not done...now I have another page called /anothergame, it needs to show 15 objects, and 10 of those are the same as /game...surely my application is getting big...how exactly should I handle passing this amount of large data to my views ? What happens if I have to have, say a header that must always contain your profile information that comes from the database ? Now for every page I must always ping the database ? Are 'global' variables allowed inside views ? Or is Client Side (say React) with and API endpoint is the way to go ? Any direction or advice would be appreciated.

Submitted June 14, 2017 at 04:26AM by HappyZombies

No comments:

Post a Comment