Web front-end optimization javascript for best practices

Source: Internet
Author: User

Web front-end optimizing JavaScript for best practice, this section has 6 rules, and several repetitions of CSS articles. Front-end optimization best practice, the most important or "practice", to understand this thing is very easy, the key is to "practice", to "execute", to "feedback" to obtain benefits.

1. Script to the bottom of the HTML code page (put Scripts at the Bottom)

When a script is downloading, the browser does nothing else (serial). So, throw it to the last side to handle it. For some functional scripts, there are some dilemmas that can be implemented. However, for domestic sites, there are many use of Google Analytics services to analyze the site data. To this point, it is absolutely feasible to put the proposal to the bottom of the page.

2. Make JavaScript and CSS External

See the description of the CSS article

3. Compact JavaScript and CSS (minify JavaScript and CSS)

See the description of the CSS article

4. Remove duplicate script (remove Duplicate Scripts)

For some historical legacy sites or forum-class sites, this is more common. To take over the maintenance of people before and after the change too much, everyone has their own set. This can lead to some potential trouble.

5. Reducing DOM Access (Minimize DOM access) has three guidance recommendations:

Cache elements that have already been accessed (cache references to accessed elements)

"Offline" update the nodes and add them to the tree (update nodes "offline" and then add them to the trees)

Avoid using JavaScript to output page layouts--it should be a CSS thing (avoid fixing layout with JavaScript)

6. Develop Smart Event handlers

In addition to the English explanation, here is a reminder of the problem with Java Script memory leaks.

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.