Simple html vs Javascript generated html?

前端 未结 12 1527
故里飘歌
故里飘歌 2020-12-30 13:09

In my web application I would like to complately avoid html and use only javascript to create web-page\'s dom tree.

What is faster writing web content in the traditi

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-30 13:33

    I find it interesting that you would consider creating a document purely through Javascript. It's actually faster to create elements using the DOM and document.createElement than .innerHTML property. This method creates the document objects directly, whereas using innerHTML requires the parser to iterate over the HTML and create the elements.

    On the other hand, using Javascript instead of writing the HTML directly would require the Javascript to be parsed and executed, creating additional overhead over the HTML parser.

提交回复
热议问题