javascript - Client-side vs server-side data manipulation -


i learned how access express local variables in client-side js:

https://stackoverflow.com/questions/34618426/express-handlebars-local-variables-in-client-side-js

but opened whole new can of worms... don't know data manipulation server side (within route) , client-side.

for example: here cutting description property of each database item, first 100 characters can used preview in featured listing collage.

//routes/index.js router.get('/', isauthenticated, function (req, res, next) {   //fetching data populate newest listings collage   user.find({role: 'organization'}).sort({datecreated: -1}).limit(6).exec(function (err, docs) {     docs.foreach(function(item){       item.description = item.description.slice(0,100);     });     console.log(docs[0].description);     res.render('index.hbs', {       user: req.user,        orgsfeatured: docs,        message: req.flash('message')     })   }); }); 

is more typical/ performant/ maintainable send entire array of objects client-side javascript sliced?

i know it's balance between running client cpu load vs server load, there must best practices. let me know if not being clear. thanks!!

in experience can't take "one-size fits all" approach.

in posted example, limiting results 6, , truncating 100 chars. doing 6 slices, wouldn't huge hit cpu-wise either side. if item.description potentially thousands of chars each, slice server side, prevent unneeded data flow. or, if thousands of users potentially calling code @ same time, , item.descriptions close 100 chars, let thousands of web browsers work.

not knowing project, possible not slice descriptions @ all? may need entire description in popover, or use may use in search/filter mechanism. if design dictates strings need truncating, let css task.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -