drol55885602 2014-05-18 19:22
浏览 50
已采纳

从数据库的文本字段中加载大量的html标记

I wonder which method will be more efficient. I have around three hundred thousand DIV tags, which looks like this:

<div class="s" style="top:200px;left:100px;margin:0 2px 0 2px;">
here_comes_200chars_of_text</div>

Every single tag has different position and margin, that's why i can't put styles in css.

I want to put whole html code into a database, and load it from there when user needs it, and there comes my question. Is it better to store html like shown above, or to make it shorter with some php code to look like this :

<d c="s" s="t:200;l:100;m:0 2 0 2;">here_comes_200chars_of_text</d>

,upload it into database and recreate normal appearance when read?

It saves 20 chars per DIV. That makes ~6 million chars saved. That's why I'm asking.

I hope you get what I mean. Best regards.

EDIT:

Typical use of web app:

User is creating large group of html objects, each representing some kind of element on the map. There are around 200 users overall, each has his own map with objects, and at one time web app won't be used by more than 20-30 users. They store data in each element of the map, between DIV tags. They can dynamically move, change margin of the separate DIVs and change content in DIVs. After editing the map, users will be able to save their work in database. That's why I wonder how to save those DIVs, which are created and modified by user.

I hope it clears my problem a little:)

  • 写回答

2条回答 默认 最新

  • dongyi9484 2014-05-18 20:08
    关注

    I suggest to create a table like this, I think is the more efficient way (similar to Vincent Decaux comment):

    CREATE TABLE `test`.`divs` (
      `text` TEXT NOT NULL,
      `top` SMALLINT NOT NULL,
      `left` SMALLINT NOT NULL,
      `margin-top` SMALLINT NOT NULL,
      `margin-bottom` SMALLINT NOT NULL,
      `margin-left` SMALLINT NOT NULL,
      `margin-right` SMALLINT NOT NULL
    );
    

    This aproach uses 4 bytes x 6 fields = 24 bytes for the style, 16 bytes less than your approach supposing that you are storing the text as ASCII. If you use another charset the saving will be bigger.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么