Javascript file fragments can theoretically improve the execution efficiency of DOM operations.

Source: Internet
Author: User

I just came here, but I haven't forgotten it yet, so I can record a point I learned last night-the file fragments in JavaScript. 1. Basic understanding of document fragments this Article fragment can improve DOM operation performance (theoretically, pay attention to it !! Theoretically) the principle of file fragmentation reduces the reflux operation on DOM modifications. The following is a simple example of DOM backflow: for example, a person who buys vinegar, liquor, and salt from a mall. He has two ways: (1) Buy all three items at a mall at a time, so that two trips can be made back and forth; (2) buy one thing and take it home, then I went back to buy the second item, and then went back to buy the third item. It showed that it would take 6 times to get back and forth. Obviously, the latter is a neurology. In this example, we want to describe the backflow operation. Now I will take a look at how to reduce DOM reflux operations by using the method of document fragmentation to Improve the Performance by combining the new DOM nodes. For example, define 10000 li nodes at a time, place them on the file fragments, and mount them at a time. Another method is to mount the node without adding a new li node. Obviously, DOM operations are performed many times, resulting in a large number of DOM operation backflow times, theoretically, the execution performance is reduced. (In theory, because the examples I made later are inconsistent with my expected results .) How to create a document fragment var oFrag = document. createDocumentFragment (); // It is used to create document fragments. Next I will paste the code + execution of my experiment: My Test method: Add 10000 li nodes and count the execution time, compare the execution time of the two to determine who has a higher performance. (1) Use the common method to mount the new node and copy code 1 <! DOCTYPE html> 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.