javascript - Formatting Number and dates dilemma -


my app using :

  • asp.net http handler back-end in order read data mysql database , return them in json format
  • react.js app front-end display data in browsers. app built using webpack.

several pages of app display dates , numbers , format them according browser's preferred language. found cutting edge feature ecmascript internationalization api , polyfill intl.js : https://github.com/andyearnshaw/intl.js. added in app's dependencies , used formatting, example:

'use strict';  var react = require('react');  var intl = require('intl');  var formatter = new intl.datetimeformat();  module.exports = react.createclass({     render : function(){         if(this.props.value) {             var formattedvalue = formatter.format(new date(this.props.value));             return (                 <span>                     {formattedvalue}                 </span>             );         }         else{             return false;         }     } }); 

so far good, found size of minified bundle.js increases after adding intl.js in dependencies : 300kb raised 900kb! understand happens because locale-data folder(https://github.com/andyearnshaw/intl.js/tree/master/locale-data) automatically added @ runtime , needed, still can't accept fact size of app's script raised 3 times because needs display formatted dates , numbers... so, thinking delegating formatting server side returns dates , numbers formatted strings within json response. that's quite easy implement , can see couple of perks of approach:

  • preserving small size of app
  • possible performance improvements

but don't see obvious shortcomings , that's suspicious. so, question - disadvantages of formatting dates , numbers on server side , sending them formatted strings within json response?

the problem require round trip server formatting, view concern , not server concern (unless you're rendering on server, don't seem doing).

instead of bundling in locales (even ones irrelevant user) makes bundle grow. shouldn't include of them bundle, instead separate separate bundle. can either @ accept-language http header on server , serve correct language, or use javascript check locale , make request specific language.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -