开发者

Template performance: static files vs hardcoded DOM

This question might be theoretical but i think some of the cases it makes sense. I am just wondering about which solution is the most efficient: loading HTML templates or build up them with DOM functions?

Both has pros/cons and there's a lot of other factors that can close off any of them: For example it's obvious that DOM-coded HTML can't be as easy to modify than the static one.

Fact: there's a zillion factors that can surely affect performance (disk IO, memory, CPU, bad code, 开发者_StackOverflowetc.).

Question: is it a good practice to use DOM-coded HTML (fragments) as templates? Or in this case i'll be fine with string concatenation?

Thanks, fabrik


Templates are faster, in my test cases (of which results I am missing now) in comparison to creating HTML by DOM.

[EDIT]: Clarification to OP:

As I said, it was long ago (6-8 months I think) when I ran the test, I have lost the results. Well, since you need to load the data from disk ONLY ONCE, it does not create that much difference. In my tests, I had 100 variables per page. That would require DOM to insert elements 100 times or templating 100 times. The results showed a ratio of 1:1.35 (running time) in favor of templates, as far as I remember. Hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜