开发者

Advice: where to situate html table content: in JS or HTML

SHORT: my python code generates a webpage with a table. i'm considering rewriting it to generate a js file instead, that holds the table contents in an array ... and then let the table be generated client-side. I am n开发者_开发技巧ot sure of the pros and cons. Anyone care to offer their experience/insight? Are there other solutions?

LONG: the web page contains a single table and an embedded gmap. the table is a set of locations with several columns of location-stats and also two navigation columns. one nav column consists of onclicks that will recenter embedded gmap to the lat,lon of the location. the other nav column consists of hrefs that open a new window with a gmap centered on the lat,lon.

Until recently, my python code would do some number crunching on a list of files, and then generate the html file. also i wrote a js file that keeps the webpage liquid upon browser window resizing.

Recently, I modified my python code so that it:

  1. placed the lat,lon info in a custom attribute of the tr elements
  2. no longer produced the nav column tds

and then wrote a js function that

  1. loops through the trs onLoad
  2. reads the lat,lon from the custom attribute
  3. inserts the nav tds

fwiw, this reduced the size of the html file by 70% while increasing the js by 10%.

ok, so now I am debating if I should go all the way and write my python code to generate 2 files

  1. an essentially abstract html file
  2. a js file containing a js array of the locations and their stats


If your API can output a JSON document with your data, you gain significant flexibility and future-proofing. This might even be something your users will want to access directly for their own external consumption. And of course your JS code can easily generate a table from this data.

However nobody here can tell you whether this is worth doing or not, as that depends entirely on the scope of your project and opportunity cost of time spent re-architecting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜