Read JS High performance summary--dom programming (i)

Source: Internet
Author: User

Dom is a language-independent API, its browser in the pretext is to use JS to achieve.

Browsers usually implement the DOM and JS independently.

In IE, the implementation name of JS is JScript, located in the Jscript.dll file, the DOM implementation is Mshtml.dll;

The DOM and rendering in Safari are implemented using the WebCore in WebKit, and JS is implemented with an independent javascriptcore engine;

Google Browser, also use WebKit in the WebCore to render the page, but the JS engine is implemented by V8;

The JS engine in Firefox is named SpiderMonkey (the latest version of the name is Tracemonkey) and is independent of the rendering engine named Gecko.

Browser JS Implementation engine DOM Implementation engine
Ie JScript (in a Jscript.dll file) Mshtml.dll
Safari The WebCore in WebKit JavaScriptCore
Chrome The WebCore in WebKit V8
Firefox SpiderMonkey (the latest version is Tracemonkey) Gecko

Two separate functions are consumed as long as they are connected to each other via an interface. Access to the DOM also generates a certain amount of consumption.

Access and modification of the DOM

There is a cost to accessing the DOM element----as the book says about the bridge fee, modifying the element is more expensive, because he causes the browser to recalculate the geometric changes of the page . Of course, the worst-case scenario is accessing or modifying elements in a loop, especially the looping operation of the collection of HTML elements.

As the above code: the problem with this code is that the-----Each loop, the element will be accessed two times, one time to read the innerHTML property value, and another rewrite it;

More efficient way to store modified content with local variables and write once at the end of the loop:

Read JS High performance summary--dom programming (i)

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.